| [dc5376a] | 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.c -- 
 | 
|---|
 | 8 | // 
 | 
|---|
 | 9 | // Author           : Peter A. Buhr
 | 
|---|
 | 10 | // Created On       : Fri Apr 22 14:59:21 2016
 | 
|---|
 | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| [3c0ec68] | 12 | // Last Modified On : Wed May 24 13:04:33 2017
 | 
|---|
 | 13 | // Update Count     : 71
 | 
|---|
| [dc5376a] | 14 | // 
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <fstream>
 | 
|---|
 | 17 | #include <math>
 | 
|---|
 | 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 | fmod( 5.0D, -2.0D ) | 5.0L % -2.0L | fmod( 5.0L, -2.0L ) | endl;
 | 
|---|
 | 25 |         sout | "remainder:" | remainder( 2.0F, 3.0F ) | remainder( 2.0D, 3.0D ) | remainder( 2.0L, 3.0L ) | endl;
 | 
|---|
 | 26 |         int quot;
 | 
|---|
 | 27 |         f = remquo( 3.6F, 0.5F, " );
 | 
|---|
 | 28 |         sout | "remquo:" | quot | f;
 | 
|---|
 | 29 |         d = remquo( 3.6D, 0.5F, " );
 | 
|---|
 | 30 |         sout | quot | d;
 | 
|---|
 | 31 |         l = remquo( 3.6L, 0.5L, " );
 | 
|---|
 | 32 |         sout | quot | l | endl;
 | 
|---|
 | 33 |         f = div( 3.6F, 0.5F, " );
 | 
|---|
 | 34 |         sout | "div:" | quot | f;
 | 
|---|
 | 35 |         d = div( 3.6D, 0.5F, " );
 | 
|---|
 | 36 |         sout | quot | d;
 | 
|---|
 | 37 |         l = div( 3.6L, 0.5L, " );
 | 
|---|
 | 38 |         sout | quot | l | endl;
 | 
|---|
 | 39 |         sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, , 1.0L ) | endl;
 | 
|---|
 | 40 |         sout | "fdim:" | fdim( 1.0F, -1.0F ) | fdim( 1.0D, -1.0D ) | fdim( 1.0L, -1.0L ) | endl;
 | 
|---|
 | 41 |         sout | "nan:" | (float)nan( "" ) | (double)nan( "" ) | (long double)nan( "" ) | endl;
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 |         //---------------------- Exponential ----------------------
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 |         sout | "exp:" | exp( 1.0F ) | exp( 1.0D ) | exp( 1.0L ) | exp( 1.0F+1.0FI ) | exp( 1.0D+1.0DI ) | exp( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 46 |         sout | "exp2:" | exp2( 1.0F ) | exp2( 1.0D ) | exp2( 1.0L ) | endl;
 | 
|---|
 | 47 |         sout | "expm1:" | expm1( 1.0F ) | expm1( 1.0D ) | expm1( 1.0L ) | endl;
 | 
|---|
 | 48 |         sout | "log:" | log( 1.0F ) | log( 1.0D ) | log( 1.0L ) | log( 1.0F+1.0FI ) | log( 1.0D+1.0DI ) | log( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 49 |         sout | "log2:" | log2( 8.0F ) | log2( 8.0D ) | log2( 8.0L ) | endl;
 | 
|---|
 | 50 |         sout | "log10:" | log10( 100.0F ) | log10( 100.0D ) | log10( 100.0L ) | endl;
 | 
|---|
 | 51 |         sout | "log1p:" | log1p( 1.0F ) | log1p( 1.0D ) | log1p( 1.0L ) | endl;
 | 
|---|
 | 52 |         sout | "ilogb:" | ilogb( 1.0F ) | ilogb( 1.0D ) | ilogb( 1.0L ) | endl;
 | 
|---|
 | 53 |         sout | "logb:" | logb( 8.0F ) | logb( 8.0D ) | logb( 8.0L ) | endl;
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |         //---------------------- Power ----------------------
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 |         sout | "sqrt:" | sqrt( 1.0F ) | sqrt( 1.0D ) | sqrt( 1.0L ) | sqrt( 1.0F+1.0FI ) | sqrt( 1.0D+1.0DI ) | sqrt( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 58 |         sout | "cbrt:" | cbrt( 27.0F ) | cbrt( 27.0D ) | cbrt( 27.0L ) | endl;
 | 
|---|
 | 59 |         sout | "hypot:" | hypot( 1.0F, -1.0F ) | hypot( 1.0D, -1.0D ) | hypot( 1.0L, -1.0L ) | endl;
 | 
|---|
 | 60 |         sout | "pow:" | pow( 1.0F, 1.0F ) | pow( 1.0D, 1.0D ) | pow( 1.0L, 1.0L ) | pow( 1.0F+1.0FI, 1.0F+1.0FI ) | pow( 1.0D+1.0DI, 1.0D+1.0DI ) | pow( 1.0DL+1.0LI, 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 |         //---------------------- Trigonometric ----------------------
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 |         sout | "sin:" | sin( 1.0F ) | sin( 1.0D ) | sin( 1.0L ) | sin( 1.0F+1.0FI ) | sin( 1.0D+1.0DI ) | sin( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 65 |         sout | "cos:" | cos( 1.0F ) | cos( 1.0D ) | cos( 1.0L ) | cos( 1.0F+1.0FI ) | cos( 1.0D+1.0DI ) | cos( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 66 |         sout | "tan:" | tan( 1.0F ) | tan( 1.0D ) | tan( 1.0L ) | tan( 1.0F+1.0FI ) | tan( 1.0D+1.0DI ) | tan( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 67 |         sout | "asin:" | asin( 1.0F ) | asin( 1.0D ) | asin( 1.0L ) | asin( 1.0F+1.0FI ) | asin( 1.0D+1.0DI ) | asin( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 68 |         sout | "acos:" | acos( 1.0F ) | acos( 1.0D ) | acos( 1.0L ) | acos( 1.0F+1.0FI ) | acos( 1.0D+1.0DI ) | acos( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 69 |         sout | "atan:" | atan( 1.0F ) | atan( 1.0D ) | atan( 1.0L ) | atan( 1.0F+1.0FI ) | atan( 1.0D+1.0DI ) | atan( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 70 |         sout | "atan2:" | atan2( 1.0F, 1.0F ) | atan2( 1.0D, 1.0D ) | atan2( 1.0L, 1.0L );
 | 
|---|
 | 71 |         sout | "atan:" | atan( 1.0F, 1.0F ) | atan( 1.0D, 1.0D ) | atan( 1.0L, 1.0L );
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 |         //---------------------- Hyperbolic ----------------------
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |         sout | "sinh:" | sinh( 1.0F ) | sinh( 1.0D ) | sinh( 1.0L ) | sinh( 1.0F+1.0FI ) | sinh( 1.0D+1.0DI ) | sinh( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 76 |         sout | "cosh:" | cosh( 1.0F ) | cosh( 1.0D ) | cosh( 1.0L ) | cosh( 1.0F+1.0FI ) | cosh( 1.0D+1.0DI ) | cosh( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 77 |         sout | "tanh:" | tanh( 1.0F ) | tanh( 1.0D ) | tanh( 1.0L ) | tanh( 1.0F+1.0FI ) | tanh( 1.0D+1.0DI ) | tanh( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 78 |         sout | "acosh:" | acosh( 1.0F ) | acosh( 1.0D ) | acosh( 1.0L ) | acosh( 1.0F+1.0FI ) | acosh( 1.0D+1.0DI ) | acosh( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 79 |         sout | "asinh:" | asinh( 1.0F ) | asinh( 1.0D ) | asinh( 1.0L ) | asinh( 1.0F+1.0FI ) | asinh( 1.0D+1.0DI ) | asinh( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 80 |         sout | "atanh:" | atanh( 1.0F ) | atanh( 1.0D ) | atanh( 1.0L ) | atanh( 1.0F+1.0FI ) | atanh( 1.0D+1.0DI ) | atanh( 1.0DL+1.0LI ) | endl;
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 |         //---------------------- Error / Gamma ----------------------
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 |         sout | "erf:" | erf( 1.0F ) | erf( 1.0D ) | erf( 1.0L ) | endl;
 | 
|---|
 | 85 |         sout | "erfc:" | erfc( 1.0F ) | erfc( 1.0D ) | erfc( 1.0L ) | endl;
 | 
|---|
 | 86 |         sout | "lgamma:" | lgamma( 4.0F ) | lgamma( 4.0D ) | lgamma( 4.0L ) | endl;
 | 
|---|
 | 87 |         int sign;
 | 
|---|
 | 88 |         f = lgamma( 4.0F, &sign );
 | 
|---|
 | 89 |         sout | "lgamma:" | f | sign;
 | 
|---|
 | 90 |         d = lgamma( 4.0D, &sign );
 | 
|---|
 | 91 |         sout | d | sign;
 | 
|---|
 | 92 |         l = lgamma( 4.0L, &sign );
 | 
|---|
 | 93 |         sout | l | sign | endl;
 | 
|---|
 | 94 |         sout | "tgamma:" | tgamma( 4.0F ) | tgamma( 4.0D ) | tgamma( 4.0L ) | endl;
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 |         //---------------------- Nearest Integer ----------------------
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 |         sout | "floor:" | floor( 1.2F ) | floor( 1.2D ) | floor( 1.2L ) | endl;
 | 
|---|
 | 99 |         sout | "ceil:" | ceil( 1.6F ) | ceil( 1.6D ) | ceil( 1.6L ) | endl;
 | 
|---|
 | 100 |         sout | "trunc:" | trunc( 3.5F ) | trunc( 3.5D ) | trunc( 3.5L ) | endl;
 | 
|---|
 | 101 |         sout | "rint:" | (float)rint( 1.5F ) | (double)rint( 1.5D ) | (long double)rint( 1.5L ) | endl;
 | 
|---|
 | 102 |         sout | "rint:" | (long int)rint( 1.5F ) | (long int)rint( 1.5D ) | (long int)rint( 1.5L ) | endl;
 | 
|---|
 | 103 |         sout | "rint:" | (long long int)rint( 1.5F ) | (long long int)rint( 1.5D ) | (long long int)rint( 1.5L ) | endl;
 | 
|---|
 | 104 |         sout | "lrint:" | lrint( 1.5F ) | lrint( 1.5D ) | lrint( 1.5L ) | endl;
 | 
|---|
 | 105 |         sout | "llrint:" | llrint( 1.5F ) | llrint( 1.5D ) | llrint( 1.5L ) | endl;
 | 
|---|
 | 106 |         sout | "nearbyint:" | nearbyint( 3.5F ) | nearbyint( 3.5D ) | nearbyint( 3.5L ) | endl;
 | 
|---|
 | 107 |         sout | "round:" | (float)round( 1.5F ) | (double)round( 1.5D ) | (long double)round( 1.5L ) | endl;
 | 
|---|
 | 108 |         sout | "round:" | (long int)round( 1.5F ) | (long int)round( 1.5D ) | (long int)round( 1.5L ) | endl;
 | 
|---|
 | 109 |         sout | "round:" | (long long int)round( 1.5F ) | (long long int)round( 1.5D ) | (long long int)round( 1.5L ) | endl;
 | 
|---|
 | 110 |         sout | "lround:" | lround( 1.5F ) | lround( 1.5D ) | lround( 1.5L ) | endl;
 | 
|---|
 | 111 |         sout | "llround:" | llround( 1.5F ) | llround( 1.5D ) | llround( 1.5L ) | endl;
 | 
|---|
 | 112 | 
 | 
|---|
 | 113 |         //---------------------- Manipulation ----------------------
 | 
|---|
 | 114 | 
 | 
|---|
 | 115 |         sout | "copysign:" | copysign( 1.0F, -1.0F ) | copysign( 1.0D, -1.0D ) | copysign( 1.0L, -1.0L ) | endl;
 | 
|---|
 | 116 |         int exp;
 | 
|---|
 | 117 |         f = frexp( 4.0F, &exp );
 | 
|---|
 | 118 |         sout | "frexp:" | f | exp;
 | 
|---|
 | 119 |         d = frexp( 4.0D, &exp );
 | 
|---|
 | 120 |         sout | d | exp;
 | 
|---|
 | 121 |         l = frexp( 4.0L, &exp );
 | 
|---|
 | 122 |         sout | l | exp | endl;
 | 
|---|
 | 123 |         sout | "ldexp:" | ldexp( 2.0F, 2 ) | ldexp( 2.0D, 2 ) | ldexp( 2.0L, 2 ) | endl;
 | 
|---|
 | 124 |         float fi;
 | 
|---|
 | 125 |         double di;
 | 
|---|
 | 126 |         long double ldi;
 | 
|---|
 | 127 |         f = modf( 2.3F, &fi );
 | 
|---|
 | 128 |         sout | "modf:" | fi | f;
 | 
|---|
 | 129 |         d = modf( 2.3D, &di );
 | 
|---|
 | 130 |         sout | di | d;
 | 
|---|
 | 131 |         l = modf( 2.3L, &ldi );
 | 
|---|
 | 132 |         sout | ldi | l;
 | 
|---|
 | 133 |         sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L ) | endl;
 | 
|---|
 | 134 |         sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L ) | endl;
 | 
|---|
 | 135 | 
 | 
|---|
 | 136 |         sout | "scalbn:" | scalbn( 2.0F, 3 ) | scalbn( 2.0D, 3 ) | scalbn( 2.0L, 3 ) | endl;
 | 
|---|
 | 137 |         sout | "scalbln:" | scalbln( 2.0F, 3L ) | scalbln( 2.0D, 3L ) | scalbln( 2.0L, 3L ) | endl;
 | 
|---|
 | 138 | } // main
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 | // Local Variables: //
 | 
|---|
 | 141 | // tab-width: 4 //
 | 
|---|
 | 142 | // compile-command: "cfa math.c" //
 | 
|---|
 | 143 | // End: //
 | 
|---|