# source:tests/math4.cfa@ee0fa3a

Last change on this file since ee0fa3a was ee0fa3a, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

restore tests math1-4 and rename associated .except for oast

• Property mode set to `100644`
File size: 13.7 KB
Line
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// math4.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Thu May 24 20:56:54 2018
13// Update Count     : 7
14//
15
16#include <fstream.hfa>
17#include <math.hfa>
18
19int main( void ) {
20        signed char sc, scr1, scr2, scr3;
21        unsigned char uc, ucr1, ucr2, ucr3;
22        short int si, sir1, sir2, sir3;
23        unsigned short int usi, usir1, usir2, usir3;
24        int i, ir1, ir2, ir3;
25        unsigned int ui, uir1, uir2, uir3;
26        long int li, lir1, lir2, lir3;
27        unsigned long int uli, ulir1, ulir2, ulir3;
28        long long int lli, llir1, llir2, llir3;
29        unsigned long long int ulli, ullir1, ullir2, ullir3;
30
31        float f;
32        double d;
33        long double l;
34
35        //---------------------- Nearest Integer ----------------------
36
37        //============================================================
38#if 1
39        sout | nl | "floor" | nl | nl;
40
41        printf( "signed char\n" );
42        for ( sc = 1; sc != 0; sc <<= 1 ) {
43                scr1 = floor( sc, sc ); scr2 = floor( sc + 2hh, sc ); scr3 = floor( -sc - 2hh, sc );
44                printf( "floor(%hhd, %hhd) = %hhd, floor(%hhd, %hhd) = %hhd, floor(%hhd, %hhd) = %hhd\n", sc, sc, scr1, sc + 2hh, sc, scr2, -sc - 2hh, sc, scr3 );
45        } // for
46        printf( "\n" );
47
48        printf( "unsigned char\n" );
49        for ( uc = 1; uc != 0; uc <<= 1 ) {
50                ucr1 = floor( uc, uc ); ucr2 = floor( uc + 2hh, uc ); ucr3 = floor( -uc - 2hh, uc );
51                printf( "floor(%hhu, %hhu) = %hhu, floor(%hhu, %hhu) = %hhu, floor(%hhu, %hhu) = %hhu\n", uc, uc, ucr1, uc + 2uhh, uc, ucr2, -uc - 2uhh, uc, ucr3 );
52        } // for
53        printf( "\n" );
54
55        printf( "short int\n" );
56        for ( si = 1; si != 0; si <<= 1 ) {
57                sir1 = floor( si, si ); sir2 = floor( si + 2hh, si ); sir3 = floor( -si - 2hh, si );
58                printf( "floor(%hd, %hd) = %hd, floor(%hd, %hd) = %hd, floor(%hd, %hd) = %hd\n", si, si, sir1, si + 2h, si, sir2, -si - 2h, si, sir3 );
59        } // for
60        printf( "\n" );
61
62        printf( "unsigned short int\n" );
63        for ( usi = 1; usi != 0; usi <<= 1 ) {
64                usir1 = floor( usi, usi ); usir2 = floor( usi + 2hh, usi ); usir3 = floor( -usi - 2hh, usi );
65                printf( "floor(%hu, %hu) = %hu, floor(%hu, %hu) = %hu, floor(%hu, %hu) = %hu\n", usi, usi, usir1, usi + 2uh, usi, usir2, -usi - 2uh, usi, usir3 );
66        } // for
67        printf( "\n" );
68
69        printf( "int\n" );
70        for ( i = 1; i != 0; i <<= 1 ) {
71                ir1 = floor( i, i ); ir2 = floor( i + 2hh, i ); ir3 = floor( -i - 2hh, i );
72                printf( "floor(%d, %d) = %d, floor(%d, %d) = %d, floor(%d, %d) = %d\n", i, i, ir1, i + 2h, i, ir2, -i - 2h, i, ir3 );
73        } // for
74        printf( "\n" );
75
76        printf( "unsigned int\n" );
77        for ( ui = 1; ui != 0; ui <<= 1 ) {
78                uir1 = floor( ui, ui ); uir2 = floor( ui + 2hh, ui ); uir3 = floor( -ui - 2hh, ui );
79                printf( "floor(%u, %u) = %u, floor(%u, %u) = %u, floor(%u, %u) = %u\n", ui, ui, uir1, ui + 2h, ui, uir2, -ui - 2h, ui, uir3 );
80        } // for
81        printf( "\n" );
82
83        printf( "long int\n" );
84        for ( li = 1; li != 0; li <<= 1 ) {
85                lir1 = floor( li, li ); lir2 = floor( li + 2hh, li ); lir3 = floor( -li - 2hh, li );
86                printf( "floor(%ld, %ld) = %ld, floor(%ld, %ld) = %ld, floor(%ld, %ld) = %ld\n", li, li, lir1, li + 2h, li, lir2, -li - 2h, li, lir3 );
87        } // for
88        printf( "\n" );
89
90        printf( "unsigned long int\n" );
91        for ( uli = 1; uli != 0; uli <<= 1 ) {
92                ulir1 = floor( uli, uli ); ulir2 = floor( uli + 2hh, uli ); ulir3 = floor( -uli - 2hh, uli );
93                printf( "floor(%lu, %lu) = %lu, floor(%lu, %lu) = %lu, floor(%lu, %lu) = %lu\n", uli, uli, ulir1, uli + 2h, uli, ulir2, -uli - 2h, uli, ulir3 );
94        } // for
95        printf( "\n" );
96
97        printf( "long long int\n" );
98        for ( lli = 1; lli != 0; lli <<= 1 ) {
99                llir1 = floor( lli, lli ); llir2 = floor( lli + 2hh, lli ); llir3 = floor( -lli - 2hh, lli );
100                printf( "floor(%lld, %lld) = %lld, floor(%lld, %lld) = %lld, floor(%lld, %lld) = %lld\n", lli, lli, llir1, lli + 2h, lli, llir2, -lli - 2h, lli, llir3 );
101        } // for
102        printf( "\n" );
103
104        printf( "unsigned long long int\n" );
105        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
106                ullir1 = floor( ulli, ulli ); ullir2 = floor( ulli + 2hh, ulli ); ullir3 = floor( -ulli - 2hh, ulli );
107                printf( "floor(%llu, %llu) = %llu, floor(%llu, %llu) = %llu, floor(%llu, %llu) = %llu\n", ulli, ulli, ullir1, ulli + 2h, ulli, ullir2, -ulli - 2h, ulli, ullir3 );
108        } // for
109        printf( "\n" );
110#endif // 0
111        //============================================================
112#if 1
113        sout | nl | "ceiling_div" | nl | nl;
114
115        printf( "signed char\n" );
116        for ( sc = 1; sc != 0; sc <<= 1 ) {
117                scr1 = ceiling_div( sc, sc ); scr2 = ceiling_div( sc + 2hh, sc ); scr3 = ceiling_div( -sc - 2hh, sc );
118                printf( "ceiling_div(%hhd, %hhd) = %hhd, ceiling_div(%hhd, %hhd) = %hhd, ceiling_div(%hhd, %hhd) = %hhd\n", sc, sc, scr1, sc + 2hh, sc, scr2, -sc - 2hh, sc, scr3 );
119        } // for
120        printf( "\n" );
121
122        printf( "unsigned char\n" );
123        for ( uc = 1; uc != 0; uc <<= 1 ) {
124                ucr1 = ceiling_div( uc, uc ); ucr2 = ceiling_div( uc + 2hh, uc ); ucr3 = ceiling_div( -uc - 2hh, uc );
125                printf( "ceiling_div(%hhu, %hhu) = %hhu, ceiling_div(%hhu, %hhu) = %hhu, ceiling_div(%hhu, %hhu) = %hhu\n", uc, uc, ucr1, uc + 2uhh, uc, ucr2, -uc - 2uhh, uc, ucr3 );
126        } // for
127        printf( "\n" );
128
129        printf( "short int\n" );
130        for ( si = 1; si != 0; si <<= 1 ) {
131                sir1 = ceiling_div( si, si ); sir2 = ceiling_div( si + 2hh, si ); sir3 = ceiling_div( -si - 2hh, si );
132                printf( "ceiling_div(%hd, %hd) = %hd, ceiling_div(%hd, %hd) = %hd, ceiling_div(%hd, %hd) = %hd\n", si, si, sir1, si + 2h, si, sir2, -si - 2h, si, sir3 );
133        } // for
134        printf( "\n" );
135
136        printf( "unsigned short int\n" );
137        for ( usi = 1; usi != 0; usi <<= 1 ) {
138                usir1 = ceiling_div( usi, usi ); usir2 = ceiling_div( usi + 2hh, usi ); usir3 = ceiling_div( -usi - 2hh, usi );
139                printf( "ceiling_div(%hu, %hu) = %hu, ceiling_div(%hu, %hu) = %hu, ceiling_div(%hu, %hu) = %hu\n", usi, usi, usir1, usi + 2uh, usi, usir2, -usi - 2uh, usi, usir3 );
140        } // for
141        printf( "\n" );
142
143        printf( "int\n" );
144        for ( i = 1; i != 0; i <<= 1 ) {
145                ir1 = ceiling_div( i, i ); ir2 = ceiling_div( i + 2hh, i ); ir3 = ceiling_div( -i - 2hh, i );
146                printf( "ceiling_div(%d, %d) = %d, ceiling_div(%d, %d) = %d, ceiling_div(%d, %d) = %d\n", i, i, ir1, i + 2h, i, ir2, -i - 2h, i, ir3 );
147        } // for
148        printf( "\n" );
149
150        printf( "unsigned int\n" );
151        for ( ui = 1; ui != 0; ui <<= 1 ) {
152                uir1 = ceiling_div( ui, ui ); uir2 = ceiling_div( ui + 2hh, ui ); uir3 = ceiling_div( -ui - 2hh, ui );
153                printf( "ceiling_div(%u, %u) = %u, ceiling_div(%u, %u) = %u, ceiling_div(%u, %u) = %u\n", ui, ui, uir1, ui + 2h, ui, uir2, -ui - 2h, ui, uir3 );
154        } // for
155        printf( "\n" );
156
157        printf( "long int\n" );
158        for ( li = 1; li != 0; li <<= 1 ) {
159                lir1 = ceiling_div( li, li ); lir2 = ceiling_div( li + 2hh, li ); lir3 = ceiling_div( -li - 2hh, li );
160                printf( "ceiling_div(%ld, %ld) = %ld, ceiling_div(%ld, %ld) = %ld, ceiling_div(%ld, %ld) = %ld\n", li, li, lir1, li + 2h, li, lir2, -li - 2h, li, lir3 );
161        } // for
162        printf( "\n" );
163
164        printf( "unsigned long int\n" );
165        for ( uli = 1; uli != 0; uli <<= 1 ) {
166                ulir1 = ceiling_div( uli, uli ); ulir2 = ceiling_div( uli + 2hh, uli ); ulir3 = ceiling_div( -uli - 2hh, uli );
167                printf( "ceiling_div(%lu, %lu) = %lu, ceiling_div(%lu, %lu) = %lu, ceiling_div(%lu, %lu) = %lu\n", uli, uli, ulir1, uli + 2h, uli, ulir2, -uli - 2h, uli, ulir3 );
168        } // for
169        printf( "\n" );
170
171        printf( "long long int\n" );
172        for ( lli = 1; lli != 0; lli <<= 1 ) {
173                llir1 = ceiling_div( lli, lli ); llir2 = ceiling_div( lli + 2hh, lli ); llir3 = ceiling_div( -lli - 2hh, lli );
174                printf( "ceiling_div(%lld, %lld) = %lld, ceiling_div(%lld, %lld) = %lld, ceiling_div(%lld, %lld) = %lld\n", lli, lli, llir1, lli + 2h, lli, llir2, -lli - 2h, lli, llir3 );
175        } // for
176        printf( "\n" );
177
178        printf( "unsigned long long int\n" );
179        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
180                ullir1 = ceiling_div( ulli, ulli ); ullir2 = ceiling_div( ulli + 2hh, ulli ); ullir3 = ceiling_div( -ulli - 2hh, ulli );
181                printf( "ceiling_div(%llu, %llu) = %llu, ceiling_div(%llu, %llu) = %llu, ceiling_div(%llu, %llu) = %llu\n", ulli, ulli, ullir1, ulli + 2h, ulli, ullir2, -ulli - 2h, ulli, ullir3 );
182        } // for
183        printf( "\n" );
184#endif // 0
185        //============================================================
186#if 1
187        sout | nl | "ceiling" | nl | nl;
188
189        printf( "signed char\n" );
190        for ( sc = 1; sc != 0; sc <<= 1 ) {
191                scr1 = ceiling( sc, sc ); scr2 = ceiling( sc + 2hh, sc ); scr3 = ceiling( -sc - 2hh, sc );
192                printf( "ceiling(%hhd, %hhd) = %hhd, ceiling(%hhd, %hhd) = %hhd, ceiling(%hhd, %hhd) = %hhd\n", sc, sc, scr1, sc + 2hh, sc, scr2, -sc - 2hh, sc, scr3 );
193        } // for
194        printf( "\n" );
195
196        printf( "unsigned char\n" );
197        for ( uc = 1; uc != 0; uc <<= 1 ) {
198                ucr1 = ceiling( uc, uc ); ucr2 = ceiling( uc + 2hh, uc ); ucr3 = ceiling( -uc - 2hh, uc );
199                printf( "ceiling(%hhu, %hhu) = %hhu, ceiling(%hhu, %hhu) = %hhu, ceiling(%hhu, %hhu) = %hhu\n", uc, uc, ucr1, uc + 2uhh, uc, ucr2, -uc - 2uhh, uc, ucr3 );
200        } // for
201        printf( "\n" );
202
203        printf( "short int\n" );
204        for ( si = 1; si != 0; si <<= 1 ) {
205                sir1 = ceiling( si, si ); sir2 = ceiling( si + 2hh, si ); sir3 = ceiling( -si - 2hh, si );
206                printf( "ceiling(%hd, %hd) = %hd, ceiling(%hd, %hd) = %hd, ceiling(%hd, %hd) = %hd\n", si, si, sir1, si + 2h, si, sir2, -si - 2h, si, sir3 );
207        } // for
208        printf( "\n" );
209
210        printf( "unsigned short int\n" );
211        for ( usi = 1; usi != 0; usi <<= 1 ) {
212                usir1 = ceiling( usi, usi ); usir2 = ceiling( usi + 2hh, usi ); usir3 = ceiling( -usi - 2hh, usi );
213                printf( "ceiling(%hu, %hu) = %hu, ceiling(%hu, %hu) = %hu, ceiling(%hu, %hu) = %hu\n", usi, usi, usir1, usi + 2uh, usi, usir2, -usi - 2uh, usi, usir3 );
214        } // for
215        printf( "\n" );
216
217        printf( "int\n" );
218        for ( i = 1; i != 0; i <<= 1 ) {
219                ir1 = ceiling( i, i ); ir2 = ceiling( i + 2hh, i ); ir3 = ceiling( -i - 2hh, i );
220                printf( "ceiling(%d, %d) = %d, ceiling(%d, %d) = %d, ceiling(%d, %d) = %d\n", i, i, ir1, i + 2h, i, ir2, -i - 2h, i, ir3 );
221        } // for
222        printf( "\n" );
223
224        printf( "unsigned int\n" );
225        for ( ui = 1; ui != 0; ui <<= 1 ) {
226                uir1 = ceiling( ui, ui ); uir2 = ceiling( ui + 2hh, ui ); uir3 = ceiling( -ui - 2hh, ui );
227                printf( "ceiling(%u, %u) = %u, ceiling(%u, %u) = %u, ceiling(%u, %u) = %u\n", ui, ui, uir1, ui + 2h, ui, uir2, -ui - 2h, ui, uir3 );
228        } // for
229        printf( "\n" );
230
231        printf( "long int\n" );
232        for ( li = 1; li != 0; li <<= 1 ) {
233                lir1 = ceiling( li, li ); lir2 = ceiling( li + 2hh, li ); lir3 = ceiling( -li - 2hh, li );
234                printf( "ceiling(%ld, %ld) = %ld, ceiling(%ld, %ld) = %ld, ceiling(%ld, %ld) = %ld\n", li, li, lir1, li + 2h, li, lir2, -li - 2h, li, lir3 );
235        } // for
236        printf( "\n" );
237
238        printf( "unsigned long int\n" );
239        for ( uli = 1; uli != 0; uli <<= 1 ) {
240                ulir1 = ceiling( uli, uli ); ulir2 = ceiling( uli + 2hh, uli ); ulir3 = ceiling( -uli - 2hh, uli );
241                printf( "ceiling(%lu, %lu) = %lu, ceiling(%lu, %lu) = %lu, ceiling(%lu, %lu) = %lu\n", uli, uli, ulir1, uli + 2h, uli, ulir2, -uli - 2h, uli, ulir3 );
242        } // for
243        printf( "\n" );
244
245        printf( "long long int\n" );
246        for ( lli = 1; lli != 0; lli <<= 1 ) {
247                llir1 = ceiling( lli, lli ); llir2 = ceiling( lli + 2hh, lli ); llir3 = ceiling( -lli - 2hh, lli );
248                printf( "ceiling(%lld, %lld) = %lld, ceiling(%lld, %lld) = %lld, ceiling(%lld, %lld) = %lld\n", lli, lli, llir1, lli + 2h, lli, llir2, -lli - 2h, lli, llir3 );
249        } // for
250        printf( "\n" );
251
252        printf( "unsigned long long int\n" );
253        for ( ulli = 1; ulli != 0; ulli <<= 1 ) {
254                ullir1 = ceiling( ulli, ulli ); ullir2 = ceiling( ulli + 2hh, ulli ); ullir3 = ceiling( -ulli - 2hh, ulli );
255                printf( "ceiling(%llu, %llu) = %llu, ceiling(%llu, %llu) = %llu, ceiling(%llu, %llu) = %llu\n", ulli, ulli, ullir1, ulli + 2h, ulli, ullir2, -ulli - 2h, ulli, ullir3 );
256        } // for
257        printf( "\n" );
258#endif // 0
259
260        sout | "floor:" | floor( 1.2F ) | floor( 1.2D ) | floor( 1.2L );
261        sout | "ceil:" | ceil( 1.6F ) | ceil( 1.6D ) | ceil( 1.6L );
262        sout | "trunc:" | trunc( 3.5F ) | trunc( 3.5D ) | trunc( 3.5L );
263        sout | "rint:" | (float)rint( 1.5F ) | (double)rint( 1.5D ) | (long double)rint( 1.5L );
264        sout | "rint:" | (long int)rint( 1.5F ) | (long int)rint( 1.5D ) | (long int)rint( 1.5L );
265        sout | "rint:" | (long long int)rint( 1.5F ) | (long long int)rint( 1.5D ) | (long long int)rint( 1.5L );
266        sout | "lrint:" | lrint( 1.5F ) | lrint( 1.5D ) | lrint( 1.5L );
267        sout | "llrint:" | llrint( 1.5F ) | llrint( 1.5D ) | llrint( 1.5L );
268        sout | "nearbyint:" | nearbyint( 3.5F ) | nearbyint( 3.5D ) | nearbyint( 3.5L );
269        sout | "round:" | (float)round( 1.5F ) | (double)round( 1.5D ) | (long double)round( 1.5L );
270        sout | "round:" | (long int)round( 1.5F ) | (long int)round( 1.5D ) | (long int)round( 1.5L );
271        sout | "round:" | (long long int)round( 1.5F ) | (long long int)round( 1.5D ) | (long long int)round( 1.5L );
272        sout | "lround:" | lround( 1.5F ) | lround( 1.5D ) | lround( 1.5L );
273        sout | "llround:" | llround( 1.5F ) | llround( 1.5D ) | llround( 1.5L );
274
275        //---------------------- Manipulation ----------------------
276
277        sout | "copysign:" | copysign( 1.0F, -1.0F ) | copysign( 1.0D, -1.0D ) | copysign( 1.0L, -1.0L );
278        int exp;
279        f = frexp( 4.0F, &exp );
280        sout | "frexp:" | f | exp | nonl;
281        d = frexp( 4.0D, &exp );
282        sout | d | exp | nonl;
283        l = frexp( 4.0L, &exp );
284        sout | l | exp;
285        sout | "ldexp:" | ldexp( 2.0F, 2 ) | ldexp( 2.0D, 2 ) | ldexp( 2.0L, 2 );
286        float fi;
287        double di;
288        long double ldi;
289        f = modf( 2.3F, &fi );
290        sout | "modf:" | fi | f | nonl;
291        d = modf( 2.3D, &di );
292        sout | di | d | nonl;
293        l = modf( 2.3L, &ldi );
294        sout | ldi | l;
295        sout | "modf:" | modf( 2.3F ) | modf( 2.3D ) | modf( 2.3L );
296        sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L );
297        sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L );
298
299        sout | "scalbn:" | scalbn( 2.0F, 3 ) | scalbn( 2.0D, 3 ) | scalbn( 2.0L, 3 );
300        sout | "scalbln:" | scalbln( 2.0F, 3L ) | scalbln( 2.0D, 3L ) | scalbln( 2.0L, 3L );
301} // main
302
303// Local Variables: //
304// tab-width: 4 //
305// compile-command: "cfa math4.cfa" //
306// End: //
Note: See TracBrowser for help on using the repository browser.