[73abe95] | 1 | // |
---|
[0a5b683] | 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. |
---|
[73abe95] | 6 | // |
---|
[dc8511c] | 7 | // math1.cfa -- |
---|
[73abe95] | 8 | // |
---|
[0a5b683] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Fri Apr 22 14:59:21 2016 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[1201d54] | 12 | // Last Modified On : Sun Jul 14 10:16:45 2019 |
---|
| 13 | // Update Count : 112 |
---|
[73abe95] | 14 | // |
---|
[0a5b683] | 15 | |
---|
[73abe95] | 16 | #include <fstream.hfa> |
---|
| 17 | #include <math.hfa> |
---|
[0a5b683] | 18 | |
---|
| 19 | int main( void ) { |
---|
| 20 | float f; |
---|
| 21 | double d; |
---|
| 22 | long double l; |
---|
| 23 | |
---|
[ac1ae2c6] | 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 ); |
---|
[200fcb3] | 26 | sout | "remainder:" | remainder( 2.0F, 3.0F ) | remainder( 2.0D, 3.0D ) | remainder( 2.0L, 3.0L ); |
---|
[0a5b683] | 27 | int quot; |
---|
| 28 | f = remquo( 3.6F, 0.5F, " ); |
---|
[200fcb3] | 29 | sout | "remquo:" | quot | f | nonl; |
---|
[0a5b683] | 30 | d = remquo( 3.6D, 0.5F, " ); |
---|
[200fcb3] | 31 | sout | quot | d | nonl; |
---|
[0a5b683] | 32 | l = remquo( 3.6L, 0.5L, " ); |
---|
[200fcb3] | 33 | sout | quot | l; |
---|
| 34 | sout | "div:" | div( 3.6F, 0.5F ) | div( 3.6D, 0.5D ) | div( 3.6L, 0.5L ); |
---|
[1201d54] | 35 | sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, 1.0L ); |
---|
[200fcb3] | 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( "" ); |
---|
[0a5b683] | 38 | |
---|
| 39 | //---------------------- Exponential ---------------------- |
---|
| 40 | |
---|
[ac1ae2c6] | 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 ); |
---|
[200fcb3] | 43 | sout | "exp2:" | exp2( 1.0F ) | exp2( 1.0D ) | exp2( 1.0L ); |
---|
| 44 | sout | "expm1:" | expm1( 1.0F ) | expm1( 1.0D ) | expm1( 1.0L ); |
---|
[ac1ae2c6] | 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 ); |
---|
[0a5b683] | 47 | |
---|
| 48 | int b = 4; |
---|
| 49 | unsigned int e = 2; |
---|
| 50 | b \= e; |
---|
[c274df2] | 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); |
---|
[ac1ae2c6] | 54 | sout | 4 \ -3 | -4 \ -3 | 4.0 \ 2.1 | (1.0f+2.0fi) \ (3.0f+2.0fi); |
---|
[c274df2] | 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; } |
---|
[65240bb] | 61 | void ?|?( ofstream & os, S s ) { (ofstream &)(os | s); ends( os ); } |
---|
[c274df2] | 62 | S s = { 4 }; |
---|
| 63 | S x = s \ 2; |
---|
| 64 | sout | x; |
---|
| 65 | sout | s.i | s \ 2u; |
---|
[0a5b683] | 66 | } // main |
---|
| 67 | |
---|
| 68 | // Local Variables: // |
---|
| 69 | // tab-width: 4 // |
---|
[dc8511c] | 70 | // compile-command: "cfa math1.cfa" // |
---|
[0a5b683] | 71 | // End: // |
---|