Debian Codegraph @

gcc/testsuite/gm2/pimlib/run/pass/testreal4.mod

raw
1 (* Copyright (C) 2009 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
17
18 MODULE testreal4 ;
19
20 FROM InOut IMPORT WriteLn, WriteString ;
21 FROM RealConversions IMPORT SetNoOfExponentDigits,
22 LongRealToString ;
23 FROM StrLib IMPORT StrEqual ;
24
25
26 PROCEDURE Assert (b: BOOLEAN) ;
27 BEGIN
28 IF NOT b
29 THEN
30 WriteString('assertion failed') ; WriteLn ;
31 r := 1
32 END
33 END Assert ;
34
35
36 VAR
37 s: ARRAY [0..40] OF CHAR ;
38 ok: BOOLEAN ;
39 r : INTEGER ;
40 BEGIN
41 r := 0 ;
42 SetNoOfExponentDigits(3) ;
43 LongRealToString(0.0123456789, -8, 15, s, ok) ;
44 Assert(StrEqual(s, '1.23456789E-002') AND ok) ;
45 IF ok
46 THEN
47 WriteString(s) ; WriteLn
48 END ;
49 IF NOT StrEqual(s, '1.23456789E-002')
50 THEN
51 WriteString('expecting 1.23456789E-002 and received ') ; WriteString(s) ; WriteLn
52 END ;
53 LongRealToString(1.23456789, -8, 15, s, ok) ;
54 Assert(StrEqual(s, '1.23456789E+000') AND ok) ;
55 IF ok
56 THEN
57 WriteString(s) ; WriteLn
58 END ;
59 IF NOT StrEqual(s, '1.23456789E+000')
60 THEN
61 WriteString('expecting 1.23456789E+000 and received ') ; WriteString(s) ; WriteLn
62 END ;
63 HALT(r)
64 END testreal4.