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 | // math.cfa -- |
---|
8 | // |
---|
9 | // Author : Peter A. Buhr |
---|
10 | // Created On : Fri Apr 22 14:59:21 2016 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Sat Feb 20 18:00:48 2021 |
---|
13 | // Update Count : 115 |
---|
14 | // |
---|
15 | |
---|
16 | #include <fstream.hfa> |
---|
17 | #include <math.hfa> |
---|
18 | |
---|
19 | int main( void ) { |
---|
20 | float f; |
---|
21 | double d; |
---|
22 | long double l; |
---|
23 | |
---|
24 | sout | "fmod:" | 5.0F % -2.0F | fmod( 5.0F, -2.0F ) | 5.0D % -2.0D | nonl; |
---|
25 | sout | fmod( 5.0D, -2.0D ) | 5.0L % -2.0L | fmod( 5.0L, -2.0L ); |
---|
26 | sout | "remainder:" | remainder( 2.0F, 3.0F ) | remainder( 2.0D, 3.0D ) | remainder( 2.0L, 3.0L ); |
---|
27 | int quot; |
---|
28 | f = remquo( 3.6F, 0.5F, " ); |
---|
29 | sout | "remquo:" | quot | f | nonl; |
---|
30 | d = remquo( 3.6D, 0.5F, " ); |
---|
31 | sout | quot | d | nonl; |
---|
32 | l = remquo( 3.6L, 0.5L, " ); |
---|
33 | sout | quot | l; |
---|
34 | sout | "div:" | div( 3.6F, 0.5F ) | div( 3.6D, 0.5D ) | div( 3.6L, 0.5L ); |
---|
35 | sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, 1.0L ); |
---|
36 | sout | "fdim:" | fdim( 1.0F, -1.0F ) | fdim( 1.0D, -1.0D ) | fdim( 1.0L, -1.0L ); |
---|
37 | sout | "nan:" | (float)nan( "" ) | (double)nan( "" ) | (long double)nan( "" ); |
---|
38 | |
---|
39 | //---------------------- Exponential ---------------------- |
---|
40 | |
---|
41 | sout | "exp:" | exp( 1.0F ) | exp( 1.0D ) | exp( 1.0L ) | nonl; |
---|
42 | sout | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0DL+1.0LI ); |
---|
43 | sout | "exp2:" | exp2( 1.0F ) | exp2( 1.0D ) | exp2( 1.0L ); |
---|
44 | sout | "expm1:" | expm1( 1.0F ) | expm1( 1.0D ) | expm1( 1.0L ); |
---|
45 | sout | "pow:" | pow( 1.0F, 1.0F ) | pow( 1.0D, 1.0D ) | pow( 1.0L, 1.0L ) | nonl; |
---|
46 | sout | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.5DL+1.5LI, 1.5DL+1.5LI ); |
---|
47 | |
---|
48 | int b = 4; |
---|
49 | unsigned int e = 2; |
---|
50 | b \= e; |
---|
51 | sout | b | "\\" | e | "= " | b \ e; |
---|
52 | sout | 'a' \ 3 | 2 \ 8 | 4 \ 3 | -4 \ 3 | 4 \ -3 | -4 \ -3; |
---|
53 | sout | 4.0 \ -3 | -4.0 \ -3 | 4.0 \ 2.1 | (1.0f+2.0fi) \ (3.0f+2.0fi); |
---|
54 | sout | 4 \ -3 | -4 \ -3 | 4.0 \ 2.1 | (1.0f+2.0fi) \ (3.0f+2.0fi); |
---|
55 | |
---|
56 | struct S { int i; }; |
---|
57 | double ?*?( double d, S s ) { return d * s.i; } |
---|
58 | double ?/?( double d, S s ) { return d / s.i; } |
---|
59 | S ?\?( S s, unsigned long y ) { return (S){ s.i \ y }; } |
---|
60 | ofstream & ?|?( ofstream & os, S s ) { return os | s.i; } |
---|
61 | void ?|?( ofstream & os, S s ) { (ofstream &)(os | s); ends( os ); } |
---|
62 | S s = { 4 }; |
---|
63 | S x = s \ 2; |
---|
64 | sout | x; |
---|
65 | sout | s.i | s \ 2u; |
---|
66 | |
---|
67 | //---------------------- Logarithm ---------------------- |
---|
68 | |
---|
69 | sout | "log:" | log( 1.0F ) | log( 1.0D ) | log( 1.0L ) | nonl; |
---|
70 | sout | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0DL+1.0LI ); |
---|
71 | sout | "log2:" | log2( 8.0F ) | log2( 8.0D ) | log2( 8.0L ); |
---|
72 | sout | "log10:" | log10( 100.0F ) | log10( 100.0D ) | log10( 100.0L ); |
---|
73 | sout | "log1p:" | log1p( 1.0F ) | log1p( 1.0D ) | log1p( 1.0L ); |
---|
74 | sout | "ilogb:" | ilogb( 1.0F ) | ilogb( 1.0D ) | ilogb( 1.0L ); |
---|
75 | sout | "logb:" | logb( 8.0F ) | logb( 8.0D ) | logb( 8.0L ); |
---|
76 | |
---|
77 | sout | "sqrt:" | sqrt( 1.0F ) | sqrt( 1.0D ) | sqrt( 1.0L ) | nonl; |
---|
78 | sout | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0DL+1.0LI ); |
---|
79 | sout | "cbrt:" | cbrt( 27.0F ) | cbrt( 27.0D ) | cbrt( 27.0L ); |
---|
80 | sout | "hypot:" | hypot( 1.0F, -1.0F ) | hypot( 1.0D, -1.0D ) | hypot( 1.0L, -1.0L ); |
---|
81 | |
---|
82 | //---------------------- Trigonometric ---------------------- |
---|
83 | |
---|
84 | sout | "sin:" | sin( 1.0F ) | sin( 1.0D ) | sin( 1.0L ) | nonl; |
---|
85 | sout | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0DL+1.0LI ); |
---|
86 | sout | "cos:" | cos( 1.0F ) | cos( 1.0D ) | cos( 1.0L ) | nonl; |
---|
87 | sout | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0DL+1.0LI ); |
---|
88 | sout | "tan:" | tan( 1.0F ) | tan( 1.0D ) | tan( 1.0L ) | nonl; |
---|
89 | sout | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0DL+1.0LI ); |
---|
90 | sout | "asin:" | asin( 1.0F ) | asin( 1.0D ) | asin( 1.0L ) | nonl; |
---|
91 | sout | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0DL+1.0LI ); |
---|
92 | sout | "acos:" | acos( 1.0F ) | acos( 1.0D ) | acos( 1.0L ) | nonl; |
---|
93 | sout | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0DL+1.0LI ); |
---|
94 | sout | "atan:" | atan( 1.0F ) | atan( 1.0D ) | atan( 1.0L ) | nonl; |
---|
95 | sout | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0DL+1.0LI ); |
---|
96 | sout | "atan2:" | atan2( 1.0F, 1.0F ) | atan2( 1.0D, 1.0D ) | atan2( 1.0L, 1.0L ) | nonl; |
---|
97 | sout | "atan:" | atan( 1.0F, 1.0F ) | atan( 1.0D, 1.0D ) | atan( 1.0L, 1.0L ); |
---|
98 | |
---|
99 | //---------------------- Hyperbolic ---------------------- |
---|
100 | |
---|
101 | sout | "sinh:" | sinh( 1.0F ) | sinh( 1.0D ) | sinh( 1.0L ) | nonl; |
---|
102 | sout | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0DL+1.0LI ); |
---|
103 | sout | "cosh:" | cosh( 1.0F ) | cosh( 1.0D ) | cosh( 1.0L ) | nonl; |
---|
104 | sout | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0DL+1.0LI ); |
---|
105 | sout | "tanh:" | tanh( 1.0F ) | tanh( 1.0D ) | tanh( 1.0L ) | nonl; |
---|
106 | sout | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0DL+1.0LI ); |
---|
107 | sout | "acosh:" | acosh( 1.0F ) | acosh( 1.0D ) | acosh( 1.0L ) | nonl; |
---|
108 | sout | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0DL+1.0LI ); |
---|
109 | sout | "asinh:" | asinh( 1.0F ) | asinh( 1.0D ) | asinh( 1.0L ) | nonl; |
---|
110 | sout | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0DL+1.0LI ); |
---|
111 | sout | "atanh:" | atanh( 1.0F ) | atanh( 1.0D ) | atanh( 1.0L ) | nonl; |
---|
112 | sout | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0DL+1.0LI ); |
---|
113 | |
---|
114 | //---------------------- Error / Gamma ---------------------- |
---|
115 | |
---|
116 | sout | "erf:" | erf( 1.0F ) | erf( 1.0D ) | erf( 1.0L ); |
---|
117 | sout | "erfc:" | erfc( 1.0F ) | erfc( 1.0D ) | erfc( 1.0L ); |
---|
118 | sout | "lgamma:" | lgamma( 4.0F ) | lgamma( 4.0D ) | lgamma( 4.0L ); |
---|
119 | int sign; |
---|
120 | f = lgamma( 4.0F, &sign ); |
---|
121 | sout | "lgamma:" | f | sign | nonl; |
---|
122 | d = lgamma( 4.0D, &sign ); |
---|
123 | sout | d | sign | nonl; |
---|
124 | l = lgamma( 4.0L, &sign ); |
---|
125 | sout | l | sign; |
---|
126 | sout | "tgamma:" | tgamma( 4.0F ) | tgamma( 4.0D ) | tgamma( 4.0L ); |
---|
127 | |
---|
128 | //---------------------- Nearest Integer ---------------------- |
---|
129 | |
---|
130 | sout | "floor:" | floor( 1.2F ) | floor( 1.2D ) | floor( 1.2L ); |
---|
131 | sout | "ceil:" | ceil( 1.6F ) | ceil( 1.6D ) | ceil( 1.6L ); |
---|
132 | sout | "trunc:" | trunc( 3.5F ) | trunc( 3.5D ) | trunc( 3.5L ); |
---|
133 | sout | "rint:" | (float)rint( 1.5F ) | (double)rint( 1.5D ) | (long double)rint( 1.5L ); |
---|
134 | sout | "rint:" | (long int)rint( 1.5F ) | (long int)rint( 1.5D ) | (long int)rint( 1.5L ); |
---|
135 | sout | "rint:" | (long long int)rint( 1.5F ) | (long long int)rint( 1.5D ) | (long long int)rint( 1.5L ); |
---|
136 | sout | "lrint:" | lrint( 1.5F ) | lrint( 1.5D ) | lrint( 1.5L ); |
---|
137 | sout | "llrint:" | llrint( 1.5F ) | llrint( 1.5D ) | llrint( 1.5L ); |
---|
138 | sout | "nearbyint:" | nearbyint( 3.5F ) | nearbyint( 3.5D ) | nearbyint( 3.5L ); |
---|
139 | sout | "round:" | (float)round( 1.5F ) | (double)round( 1.5D ) | (long double)round( 1.5L ); |
---|
140 | sout | "round:" | (long int)round( 1.5F ) | (long int)round( 1.5D ) | (long int)round( 1.5L ); |
---|
141 | sout | "round:" | (long long int)round( 1.5F ) | (long long int)round( 1.5D ) | (long long int)round( 1.5L ); |
---|
142 | sout | "lround:" | lround( 1.5F ) | lround( 1.5D ) | lround( 1.5L ); |
---|
143 | sout | "llround:" | llround( 1.5F ) | llround( 1.5D ) | llround( 1.5L ); |
---|
144 | |
---|
145 | //---------------------- Manipulation ---------------------- |
---|
146 | |
---|
147 | sout | "copysign:" | copysign( 1.0F, -1.0F ) | copysign( 1.0D, -1.0D ) | copysign( 1.0L, -1.0L ); |
---|
148 | int exp; |
---|
149 | f = frexp( 4.0F, &exp ); |
---|
150 | sout | "frexp:" | f | exp | nonl; |
---|
151 | d = frexp( 4.0D, &exp ); |
---|
152 | sout | d | exp | nonl; |
---|
153 | l = frexp( 4.0L, &exp ); |
---|
154 | sout | l | exp; |
---|
155 | sout | "ldexp:" | ldexp( 2.0F, 2 ) | ldexp( 2.0D, 2 ) | ldexp( 2.0L, 2 ); |
---|
156 | float fi; |
---|
157 | double di; |
---|
158 | long double ldi; |
---|
159 | f = modf( 2.3F, &fi ); |
---|
160 | sout | "modf:" | fi | f | nonl; |
---|
161 | d = modf( 2.3D, &di ); |
---|
162 | sout | di | d | nonl; |
---|
163 | l = modf( 2.3L, &ldi ); |
---|
164 | sout | ldi | l; |
---|
165 | sout | "modf:" | modf( 2.3F ) | modf( 2.3D ) | modf( 2.3L ); |
---|
166 | sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L ); |
---|
167 | sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L ); |
---|
168 | |
---|
169 | sout | "scalbn:" | scalbn( 2.0F, 3 ) | scalbn( 2.0D, 3 ) | scalbn( 2.0L, 3 ); |
---|
170 | sout | "scalbln:" | scalbln( 2.0F, 3L ) | scalbln( 2.0D, 3L ) | scalbln( 2.0L, 3L ); |
---|
171 | } // main |
---|