]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/gm2-libs-log/FloatingUtilities.mod
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / gm2-libs-log / FloatingUtilities.mod
CommitLineData
1eee94d3
GM
1(* FloatingUtilities.mod provides a Logitech compatible library.
2
a945c346 3Copyright (C) 2005-2024 Free Software Foundation, Inc.
1eee94d3
GM
4Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
5
6This file is part of GNU Modula-2.
7
8GNU Modula-2 is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GNU Modula-2 is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25<http://www.gnu.org/licenses/>. *)
26
27IMPLEMENTATION MODULE FloatingUtilities ;
28
29
30(*
31 Frac - returns the fractional component of, r.
32*)
33
34PROCEDURE Frac (r: REAL) : REAL ;
35BEGIN
36 RETURN r-VAL(REAL, Int(r))
37END Frac ;
38
39
40(*
41 Int - returns the integer part of r. It rounds the value towards zero.
42*)
43
44PROCEDURE Int (r: REAL) : INTEGER ;
45BEGIN
46 IF r>=0.0
47 THEN
48 RETURN VAL(INTEGER, r)
49 ELSE
50 RETURN -VAL(INTEGER, -r)
51 END
52END Int ;
53
54
55(*
56 Round - returns the number rounded to the nearest integer.
57 It rounds away from zero.
58*)
59
60PROCEDURE Round (r: REAL) : INTEGER ;
61BEGIN
62 IF r>=0.0
63 THEN
64 RETURN Int(r+0.5)
65 ELSE
66 RETURN Int(r-0.5)
67 END
68END Round ;
69
70
71(*
72 Float - returns a REAL value corresponding to, i.
73*)
74
75PROCEDURE Float (i: INTEGER) : REAL ;
76BEGIN
77 RETURN VAL(REAL, i)
78END Float ;
79
80
81(*
82 Trunc - round to the nearest integer not larger in absolute
83 value.
84*)
85
86PROCEDURE Trunc (r: REAL) : INTEGER ;
87BEGIN
88 RETURN TRUNC(r)
89END Trunc ;
90
91
92(*
93 Fracl - returns the fractional component of, r.
94*)
95
96PROCEDURE Fracl (r: LONGREAL) : LONGREAL ;
97BEGIN
98 RETURN r-VAL(LONGREAL, Intl(r))
99END Fracl ;
100
101
102(*
103 Intl - returns the integer part of r. It rounds the value towards zero.
104*)
105
106PROCEDURE Intl (r: LONGREAL) : LONGINT ;
107BEGIN
108 IF r>=0.0
109 THEN
110 RETURN VAL(LONGINT, r)
111 ELSE
112 RETURN -VAL(LONGINT, -r)
113 END
114END Intl ;
115
116
117(*
118 Roundl - returns the number rounded to the nearest integer.
119*)
120
121PROCEDURE Roundl (r: LONGREAL) : LONGINT ;
122BEGIN
123 IF r>=0.0
124 THEN
125 RETURN Intl(r+0.5)
126 ELSE
127 RETURN Intl(r-0.5)
128 END
129END Roundl ;
130
131
132(*
133 Floatl - returns a REAL value corresponding to, i.
134*)
135
136PROCEDURE Floatl (i: INTEGER) : LONGREAL ;
137BEGIN
138 RETURN VAL(LONGREAL, i)
139END Floatl ;
140
141
142(*
143 Truncl - round to the nearest integer not larger in absolute
144 value.
145*)
146
147PROCEDURE Truncl (r: LONGREAL) : LONGINT ;
148BEGIN
149 RETURN VAL(LONGINT, r)
150END Truncl ;
151
152
153END FloatingUtilities.