]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gm2/pimlib/run/pass/testreal2.mod
Merge modula-2 front end onto gcc.
[thirdparty/gcc.git] / gcc / testsuite / gm2 / pimlib / run / pass / testreal2.mod
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 testreal2 ;
19
20 FROM FpuIO IMPORT WriteLongReal, LongRealToStr ;
21 FROM StrLib IMPORT StrEqual ;
22 FROM libc IMPORT exit, printf ;
23 FROM StrIO IMPORT WriteLn ;
24 FROM FIO IMPORT FlushBuffer, StdOut ;
25
26 PROCEDURE Assert (b: BOOLEAN; l: CARDINAL) ;
27 BEGIN
28 IF NOT b
29 THEN
30 FlushBuffer(StdOut) ;
31 printf("%s:%d:regression test failed during execution\n",
32 __FILE__, l) ;
33 r := 1
34 END
35 END Assert ;
36
37 VAR
38 a: LONGREAL;
39 s: ARRAY [0..20] OF CHAR ;
40 r: INTEGER ;
41 BEGIN
42 r := 0 ;
43
44 a := -0.01 ;
45 WriteLongReal(a, 5, 2) ; WriteLn ;
46 LongRealToStr(a, 5, 2, s) ;
47 Assert(StrEqual(s, '-0.01'), __LINE__) ;
48
49 a := 0.1 ;
50 WriteLongReal(a,15,11) ; WriteLn ;
51 LongRealToStr(a, 15, 11, s) ;
52 Assert(StrEqual(s, ' 0.10000000000'), __LINE__) ;
53
54 a := 0.01 ;
55 WriteLongReal(a, 5, 2) ; WriteLn ;
56 LongRealToStr(a, 5, 2, s) ;
57 Assert(StrEqual(s, ' 0.01'), __LINE__) ;
58
59 a := 0.000000001 ;
60 WriteLongReal(a, 11, 9) ; WriteLn ;
61 LongRealToStr(a, 11, 9, s) ;
62 Assert(StrEqual(s, '0.000000001'), __LINE__) ;
63
64 a := 0.00000001 ;
65 WriteLongReal(a, 10, 8) ; WriteLn ;
66 LongRealToStr(a, 10, 8, s) ;
67 Assert(StrEqual(s, '0.00000001'), __LINE__) ;
68
69 a := 0.25 ;
70 WriteLongReal(a,15,11) ; WriteLn ;
71 LongRealToStr(a, 15, 11, s) ;
72 Assert(StrEqual(s, ' 0.25000000000'), __LINE__) ;
73
74 a := 0.12 ;
75 WriteLongReal(a, 5, 2) ; WriteLn ;
76 LongRealToStr(a, 5, 2, s) ;
77 Assert(StrEqual(s, ' 0.12'), __LINE__) ;
78
79 a := 0.001 ;
80 WriteLongReal(a, 6, 3) ; WriteLn ;
81 LongRealToStr(a, 6, 3, s) ;
82 Assert(StrEqual(s, ' 0.001'), __LINE__) ;
83
84 a := 0.0001 ;
85 WriteLongReal(a, 7, 4) ; WriteLn ;
86 LongRealToStr(a, 7, 4, s) ;
87 Assert(StrEqual(s, ' 0.0001'), __LINE__) ;
88
89 a := 0.00001 ;
90 WriteLongReal(a, 8, 5) ; WriteLn ;
91 LongRealToStr(a, 8, 5, s) ;
92 Assert(StrEqual(s, ' 0.00001'), __LINE__) ;
93 END testreal2.