| 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 --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Peter A. Buhr
 | 
|---|
| 10 | // Created On       : Mon Apr 18 23:37:04 2016
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Mon Aug 24 08:56:20 2020
 | 
|---|
| 13 | // Update Count     : 126
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #pragma once
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <math.h>
 | 
|---|
| 19 | #include <complex.h>
 | 
|---|
| 20 | 
 | 
|---|
| 21 | //---------------------------------------
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #include "common.hfa"
 | 
|---|
| 24 | 
 | 
|---|
| 25 | //---------------------- General ----------------------
 | 
|---|
| 26 | 
 | 
|---|
| 27 | static inline {
 | 
|---|
| 28 |         float ?%?( float x, float y ) { return fmodf( x, y ); }
 | 
|---|
| 29 |         float fmod( float x, float y ) { return fmodf( x, y ); }
 | 
|---|
| 30 |         double ?%?( double x, double y ) { return fmod( x, y ); }
 | 
|---|
| 31 |         // extern "C" { double fmod( double, double ); }
 | 
|---|
| 32 |         long double ?%?( long double x, long double y ) { return fmodl( x, y ); }
 | 
|---|
| 33 |         long double fmod( long double x, long double y ) { return fmodl( x, y ); }
 | 
|---|
| 34 | 
 | 
|---|
| 35 |         float remainder( float x, float y ) { return remainderf( x, y ); }
 | 
|---|
| 36 |         // extern "C" { double remainder( double, double ); }
 | 
|---|
| 37 |         long double remainder( long double x, long double y ) { return remainderl( x, y ); }
 | 
|---|
| 38 | 
 | 
|---|
| 39 |         float remquo( float x, float y, int * quo ) { return remquof( x, y, quo ); }
 | 
|---|
| 40 |         // extern "C" { double remquo( double x, double y, int * quo ); }
 | 
|---|
| 41 |         long double remquo( long double x, long double y, int * quo ) { return remquol( x, y, quo ); }
 | 
|---|
| 42 |         [ int, float ] remquo( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; }
 | 
|---|
| 43 |         [ int, double ] remquo( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; }
 | 
|---|
| 44 |         [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; }
 | 
|---|
| 45 | 
 | 
|---|
| 46 |         [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; }
 | 
|---|
| 47 |         [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; }
 | 
|---|
| 48 |         [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; }
 | 
|---|
| 49 | 
 | 
|---|
| 50 |         float fma( float x, float y, float z ) { return fmaf( x, y, z ); }
 | 
|---|
| 51 |         // extern "C" { double fma( double, double, double ); }
 | 
|---|
| 52 |         long double fma( long double x, long double y, long double z ) { return fmal( x, y, z ); }
 | 
|---|
| 53 | 
 | 
|---|
| 54 |         float fdim( float x, float y ) { return fdimf( x, y ); }
 | 
|---|
| 55 |         // extern "C" { double fdim( double, double ); }
 | 
|---|
| 56 |         long double fdim( long double x, long double y ) { return fdiml( x, y ); }
 | 
|---|
| 57 | 
 | 
|---|
| 58 |         float nan( const char tag[] ) { return nanf( tag ); }
 | 
|---|
| 59 |         // extern "C" { double nan( const char [] ); }
 | 
|---|
| 60 |         long double nan( const char tag[] ) { return nanl( tag ); }
 | 
|---|
| 61 | } // distribution
 | 
|---|
| 62 | 
 | 
|---|
| 63 | //---------------------- Exponential ----------------------
 | 
|---|
| 64 | 
 | 
|---|
| 65 | static inline {
 | 
|---|
| 66 |         float exp( float x ) { return expf( x ); }
 | 
|---|
| 67 |         // extern "C" { double exp( double ); }
 | 
|---|
| 68 |         long double exp( long double x ) { return expl( x ); }
 | 
|---|
| 69 |         float _Complex exp( float _Complex x ) { return cexpf( x ); }
 | 
|---|
| 70 |         double _Complex exp( double _Complex x ) { return cexp( x ); }
 | 
|---|
| 71 |         long double _Complex exp( long double _Complex x ) { return cexpl( x ); }
 | 
|---|
| 72 | 
 | 
|---|
| 73 |         float exp2( float x ) { return exp2f( x ); }
 | 
|---|
| 74 |         // extern "C" { double exp2( double ); }
 | 
|---|
| 75 |         long double exp2( long double x ) { return exp2l( x ); }
 | 
|---|
| 76 |         //float _Complex exp2( float _Complex x ) { return cexp2f( x ); }
 | 
|---|
| 77 |         //double _Complex exp2( double _Complex x ) { return cexp2( x ); }
 | 
|---|
| 78 |         //long double _Complex exp2( long double _Complex x ) { return cexp2l( x ); }
 | 
|---|
| 79 | 
 | 
|---|
| 80 |         float expm1( float x ) { return expm1f( x ); }
 | 
|---|
| 81 |         // extern "C" { double expm1( double ); }
 | 
|---|
| 82 |         long double expm1( long double x ) { return expm1l( x ); }
 | 
|---|
| 83 | 
 | 
|---|
| 84 |         float pow( float x, float y ) { return powf( x, y ); }
 | 
|---|
| 85 |         // extern "C" { double pow( double, double ); }
 | 
|---|
| 86 |         long double pow( long double x, long double y ) { return powl( x, y ); }
 | 
|---|
| 87 |         float _Complex pow( float _Complex x, float _Complex y ) { return cpowf( x, y ); }
 | 
|---|
| 88 |         double _Complex pow( double _Complex x, double _Complex y ) { return cpow( x, y ); }
 | 
|---|
| 89 |         long double _Complex pow( long double _Complex x, long double _Complex y ) { return cpowl( x, y ); }
 | 
|---|
| 90 | } // distribution
 | 
|---|
| 91 | 
 | 
|---|
| 92 | //---------------------- Logarithm ----------------------
 | 
|---|
| 93 | 
 | 
|---|
| 94 | static inline {
 | 
|---|
| 95 |         float log( float x ) { return logf( x ); }
 | 
|---|
| 96 |         // extern "C" { double log( double ); }
 | 
|---|
| 97 |         long double log( long double x ) { return logl( x ); }
 | 
|---|
| 98 |         float _Complex log( float _Complex x ) { return clogf( x ); }
 | 
|---|
| 99 |         double _Complex log( double _Complex x ) { return clog( x ); }
 | 
|---|
| 100 |         long double _Complex log( long double _Complex x ) { return clogl( x ); }
 | 
|---|
| 101 | 
 | 
|---|
| 102 |         float log2( float x ) { return log2f( x ); }
 | 
|---|
| 103 |         // extern "C" { double log2( double ); }
 | 
|---|
| 104 |         long double log2( long double x ) { return log2l( x ); }
 | 
|---|
| 105 |         // float _Complex log2( float _Complex x ) { return clog2f( x ); }
 | 
|---|
| 106 |         // double _Complex log2( double _Complex x ) { return clog2( x ); }
 | 
|---|
| 107 |         // long double _Complex log2( long double _Complex x ) { return clog2l( x ); }
 | 
|---|
| 108 | 
 | 
|---|
| 109 |         float log10( float x ) { return log10f( x ); }
 | 
|---|
| 110 |         // extern "C" { double log10( double ); }
 | 
|---|
| 111 |         long double log10( long double x ) { return log10l( x ); }
 | 
|---|
| 112 |         // float _Complex log10( float _Complex x ) { return clog10f( x ); }
 | 
|---|
| 113 |         // double _Complex log10( double _Complex x ) { return clog10( x ); }
 | 
|---|
| 114 |         // long double _Complex log10( long double _Complex x ) { return clog10l( x ); }
 | 
|---|
| 115 | 
 | 
|---|
| 116 |         float log1p( float x ) { return log1pf( x ); }
 | 
|---|
| 117 |         // extern "C" { double log1p( double ); }
 | 
|---|
| 118 |         long double log1p( long double x ) { return log1pl( x ); }
 | 
|---|
| 119 | 
 | 
|---|
| 120 |         int ilogb( float x ) { return ilogbf( x ); }
 | 
|---|
| 121 |         // extern "C" { int ilogb( double ); }
 | 
|---|
| 122 |         int ilogb( long double x ) { return ilogbl( x ); }
 | 
|---|
| 123 | 
 | 
|---|
| 124 |         float logb( float x ) { return logbf( x ); }
 | 
|---|
| 125 |         // extern "C" { double logb( double ); }
 | 
|---|
| 126 |         long double logb( long double x ) { return logbl( x ); }
 | 
|---|
| 127 | 
 | 
|---|
| 128 |         float sqrt( float x ) { return sqrtf( x ); }
 | 
|---|
| 129 |         // extern "C" { double sqrt( double ); }
 | 
|---|
| 130 |         long double sqrt( long double x ) { return sqrtl( x ); }
 | 
|---|
| 131 |         float _Complex sqrt( float _Complex x ) { return csqrtf( x ); }
 | 
|---|
| 132 |         double _Complex sqrt( double _Complex x ) { return csqrt( x ); }
 | 
|---|
| 133 |         long double _Complex sqrt( long double _Complex x ) { return csqrtl( x ); }
 | 
|---|
| 134 | 
 | 
|---|
| 135 |         float cbrt( float x ) { return cbrtf( x ); }
 | 
|---|
| 136 |         // extern "C" { double cbrt( double ); }
 | 
|---|
| 137 |         long double cbrt( long double x ) { return cbrtl( x ); }
 | 
|---|
| 138 | 
 | 
|---|
| 139 |         float hypot( float x, float y ) { return hypotf( x, y ); }
 | 
|---|
| 140 |         // extern "C" { double hypot( double, double ); }
 | 
|---|
| 141 |         long double hypot( long double x, long double y ) { return hypotl( x, y ); }
 | 
|---|
| 142 | } // distribution
 | 
|---|
| 143 | 
 | 
|---|
| 144 | //---------------------- Trigonometric ----------------------
 | 
|---|
| 145 | 
 | 
|---|
| 146 | static inline {
 | 
|---|
| 147 |         float sin( float x ) { return sinf( x ); }
 | 
|---|
| 148 |         // extern "C" { double sin( double ); }
 | 
|---|
| 149 |         long double sin( long double x ) { return sinl( x ); }
 | 
|---|
| 150 |         float _Complex sin( float _Complex x ) { return csinf( x ); }
 | 
|---|
| 151 |         double _Complex sin( double _Complex x ) { return csin( x ); }
 | 
|---|
| 152 |         long double _Complex sin( long double _Complex x ) { return csinl( x ); }
 | 
|---|
| 153 | 
 | 
|---|
| 154 |         float cos( float x ) { return cosf( x ); }
 | 
|---|
| 155 |         // extern "C" { double cos( double ); }
 | 
|---|
| 156 |         long double cos( long double x ) { return cosl( x ); }
 | 
|---|
| 157 |         float _Complex cos( float _Complex x ) { return ccosf( x ); }
 | 
|---|
| 158 |         double _Complex cos( double _Complex x ) { return ccos( x ); }
 | 
|---|
| 159 |         long double _Complex cos( long double _Complex x ) { return ccosl( x ); }
 | 
|---|
| 160 | 
 | 
|---|
| 161 |         float tan( float x ) { return tanf( x ); }
 | 
|---|
| 162 |         // extern "C" { double tan( double ); }
 | 
|---|
| 163 |         long double tan( long double x ) { return tanl( x ); }
 | 
|---|
| 164 |         float _Complex tan( float _Complex x ) { return ctanf( x ); }
 | 
|---|
| 165 |         double _Complex tan( double _Complex x ) { return ctan( x ); }
 | 
|---|
| 166 |         long double _Complex tan( long double _Complex x ) { return ctanl( x ); }
 | 
|---|
| 167 | 
 | 
|---|
| 168 |         float asin( float x ) { return asinf( x ); }
 | 
|---|
| 169 |         // extern "C" { double asin( double ); }
 | 
|---|
| 170 |         long double asin( long double x ) { return asinl( x ); }
 | 
|---|
| 171 |         float _Complex asin( float _Complex x ) { return casinf( x ); }
 | 
|---|
| 172 |         double _Complex asin( double _Complex x ) { return casin( x ); }
 | 
|---|
| 173 |         long double _Complex asin( long double _Complex x ) { return casinl( x ); }
 | 
|---|
| 174 | 
 | 
|---|
| 175 |         float acos( float x ) { return acosf( x ); }
 | 
|---|
| 176 |         // extern "C" { double acos( double ); }
 | 
|---|
| 177 |         long double acos( long double x ) { return acosl( x ); }
 | 
|---|
| 178 |         float _Complex acos( float _Complex x ) { return cacosf( x ); }
 | 
|---|
| 179 |         double _Complex acos( double _Complex x ) { return cacos( x ); }
 | 
|---|
| 180 |         long double _Complex acos( long double _Complex x ) { return cacosl( x ); }
 | 
|---|
| 181 | 
 | 
|---|
| 182 |         float atan( float x ) { return atanf( x ); }
 | 
|---|
| 183 |         // extern "C" { double atan( double ); }
 | 
|---|
| 184 |         long double atan( long double x ) { return atanl( x ); }
 | 
|---|
| 185 |         float _Complex atan( float _Complex x ) { return catanf( x ); }
 | 
|---|
| 186 |         double _Complex atan( double _Complex x ) { return catan( x ); }
 | 
|---|
| 187 |         long double _Complex atan( long double _Complex x ) { return catanl( x ); }
 | 
|---|
| 188 | 
 | 
|---|
| 189 |         float atan2( float x, float y ) { return atan2f( x, y ); }
 | 
|---|
| 190 |         // extern "C" { double atan2( double, double ); }
 | 
|---|
| 191 |         long double atan2( long double x, long double y ) { return atan2l( x, y ); }
 | 
|---|
| 192 | 
 | 
|---|
| 193 |         // alternative name for atan2
 | 
|---|
| 194 |         float atan( float x, float y ) { return atan2f( x, y ); }
 | 
|---|
| 195 |         double atan( double x, double y ) { return atan2( x, y ); }
 | 
|---|
| 196 |         long double atan( long double x, long double y ) { return atan2l( x, y ); }
 | 
|---|
| 197 | } // distribution
 | 
|---|
| 198 | 
 | 
|---|
| 199 | //---------------------- Hyperbolic ----------------------
 | 
|---|
| 200 | 
 | 
|---|
| 201 | static inline {
 | 
|---|
| 202 |         float sinh( float x ) { return sinhf( x ); }
 | 
|---|
| 203 |         // extern "C" { double sinh( double ); }
 | 
|---|
| 204 |         long double sinh( long double x ) { return sinhl( x ); }
 | 
|---|
| 205 |         float _Complex sinh( float _Complex x ) { return csinhf( x ); }
 | 
|---|
| 206 |         double _Complex sinh( double _Complex x ) { return csinh( x ); }
 | 
|---|
| 207 |         long double _Complex sinh( long double _Complex x ) { return csinhl( x ); }
 | 
|---|
| 208 | 
 | 
|---|
| 209 |         float cosh( float x ) { return coshf( x ); }
 | 
|---|
| 210 |         // extern "C" { double cosh( double ); }
 | 
|---|
| 211 |         long double cosh( long double x ) { return coshl( x ); }
 | 
|---|
| 212 |         float _Complex cosh( float _Complex x ) { return ccoshf( x ); }
 | 
|---|
| 213 |         double _Complex cosh( double _Complex x ) { return ccosh( x ); }
 | 
|---|
| 214 |         long double _Complex cosh( long double _Complex x ) { return ccoshl( x ); }
 | 
|---|
| 215 | 
 | 
|---|
| 216 |         float tanh( float x ) { return tanhf( x ); }
 | 
|---|
| 217 |         // extern "C" { double tanh( double ); }
 | 
|---|
| 218 |         long double tanh( long double x ) { return tanhl( x ); }
 | 
|---|
| 219 |         float _Complex tanh( float _Complex x ) { return ctanhf( x ); }
 | 
|---|
| 220 |         double _Complex tanh( double _Complex x ) { return ctanh( x ); }
 | 
|---|
| 221 |         long double _Complex tanh( long double _Complex x ) { return ctanhl( x ); }
 | 
|---|
| 222 | 
 | 
|---|
| 223 |         float asinh( float x ) { return asinhf( x ); }
 | 
|---|
| 224 |         // extern "C" { double asinh( double ); }
 | 
|---|
| 225 |         long double asinh( long double x ) { return asinhl( x ); }
 | 
|---|
| 226 |         float _Complex asinh( float _Complex x ) { return casinhf( x ); }
 | 
|---|
| 227 |         double _Complex asinh( double _Complex x ) { return casinh( x ); }
 | 
|---|
| 228 |         long double _Complex asinh( long double _Complex x ) { return casinhl( x ); }
 | 
|---|
| 229 | 
 | 
|---|
| 230 |         float acosh( float x ) { return acoshf( x ); }
 | 
|---|
| 231 |         // extern "C" { double acosh( double ); }
 | 
|---|
| 232 |         long double acosh( long double x ) { return acoshl( x ); }
 | 
|---|
| 233 |         float _Complex acosh( float _Complex x ) { return cacoshf( x ); }
 | 
|---|
| 234 |         double _Complex acosh( double _Complex x ) { return cacosh( x ); }
 | 
|---|
| 235 |         long double _Complex acosh( long double _Complex x ) { return cacoshl( x ); }
 | 
|---|
| 236 | 
 | 
|---|
| 237 |         float atanh( float x ) { return atanhf( x ); }
 | 
|---|
| 238 |         // extern "C" { double atanh( double ); }
 | 
|---|
| 239 |         long double atanh( long double x ) { return atanhl( x ); }
 | 
|---|
| 240 |         float _Complex atanh( float _Complex x ) { return catanhf( x ); }
 | 
|---|
| 241 |         double _Complex atanh( double _Complex x ) { return catanh( x ); }
 | 
|---|
| 242 |         long double _Complex atanh( long double _Complex x ) { return catanhl( x ); }
 | 
|---|
| 243 | } // distribution
 | 
|---|
| 244 | 
 | 
|---|
| 245 | //---------------------- Error / Gamma ----------------------
 | 
|---|
| 246 | 
 | 
|---|
| 247 | static inline {
 | 
|---|
| 248 |         float erf( float x ) { return erff( x ); }
 | 
|---|
| 249 |         // extern "C" { double erf( double ); }
 | 
|---|
| 250 |         long double erf( long double x ) { return erfl( x ); }
 | 
|---|
| 251 |         // float _Complex erf( float _Complex );
 | 
|---|
| 252 |         // double _Complex erf( double _Complex );
 | 
|---|
| 253 |         // long double _Complex erf( long double _Complex );
 | 
|---|
| 254 | 
 | 
|---|
| 255 |         float erfc( float x ) { return erfcf( x ); }
 | 
|---|
| 256 |         // extern "C" { double erfc( double ); }
 | 
|---|
| 257 |         long double erfc( long double x ) { return erfcl( x ); }
 | 
|---|
| 258 |         // float _Complex erfc( float _Complex );
 | 
|---|
| 259 |         // double _Complex erfc( double _Complex );
 | 
|---|
| 260 |         // long double _Complex erfc( long double _Complex );
 | 
|---|
| 261 | 
 | 
|---|
| 262 |         float lgamma( float x ) { return lgammaf( x ); }
 | 
|---|
| 263 |         // extern "C" { double lgamma( double ); }
 | 
|---|
| 264 |         long double lgamma( long double x ) { return lgammal( x ); }
 | 
|---|
| 265 |         float lgamma( float x, int * sign ) { return lgammaf_r( x, sign ); }
 | 
|---|
| 266 |         double lgamma( double x, int * sign ) { return lgamma_r( x, sign ); }
 | 
|---|
| 267 |         long double lgamma( long double x, int * sign ) { return lgammal_r( x, sign ); }
 | 
|---|
| 268 | 
 | 
|---|
| 269 |         float tgamma( float x ) { return tgammaf( x ); }
 | 
|---|
| 270 |         // extern "C" { double tgamma( double ); }
 | 
|---|
| 271 |         long double tgamma( long double x ) { return tgammal( x ); }
 | 
|---|
| 272 | } // distribution
 | 
|---|
| 273 | 
 | 
|---|
| 274 | //---------------------- Nearest Integer ----------------------
 | 
|---|
| 275 | 
 | 
|---|
| 276 | static inline {
 | 
|---|
| 277 |         signed char floor( signed char n, signed char align ) { return n / align * align; }
 | 
|---|
| 278 |         unsigned char floor( unsigned char n, unsigned char align ) { return n / align * align; }
 | 
|---|
| 279 |         short int floor( short int n, short int align ) { return n / align * align; }
 | 
|---|
| 280 |         unsigned short int floor( unsigned short int n, unsigned short int align ) { return n / align * align; }
 | 
|---|
| 281 |         int floor( int n, int align ) { return n / align * align; }
 | 
|---|
| 282 |         unsigned int floor( unsigned int n, unsigned int align ) { return n / align * align; }
 | 
|---|
| 283 |         long int floor( long int n, long int align ) { return n / align * align; }
 | 
|---|
| 284 |         unsigned long int floor( unsigned long int n, unsigned long int align ) { return n / align * align; }
 | 
|---|
| 285 |         long long int floor( long long int n, long long int align ) { return n / align * align; }
 | 
|---|
| 286 |         unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return n / align * align; }
 | 
|---|
| 287 | 
 | 
|---|
| 288 |         // forall( otype T | { T ?/?( T, T ); T ?*?( T, T ); } )
 | 
|---|
| 289 |         // T floor( T n, T align ) { return n / align * align; }
 | 
|---|
| 290 | 
 | 
|---|
| 291 |         signed char ceiling_div( signed char n, char align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 292 |         unsigned char ceiling_div( unsigned char n, unsigned char align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 293 |         short int ceiling_div( short int n, short int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 294 |         unsigned short int ceiling_div( unsigned short int n, unsigned short int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 295 |         int ceiling_div( int n, int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 296 |         unsigned int ceiling_div( unsigned int n, unsigned int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 297 |         long int ceiling_div( long int n, long int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 298 |         unsigned long int ceiling_div( unsigned long int n, unsigned long int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 299 |         long long int ceiling_div( long long int n, long long int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 300 |         unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; }
 | 
|---|
| 301 | 
 | 
|---|
| 302 |         // forall( otype T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )
 | 
|---|
| 303 |         // T ceiling_div( T n, T align ) { verify( is_pow2( align ) );return (n + (align - 1)) / align; }
 | 
|---|
| 304 |         
 | 
|---|
| 305 |         // gcc notices the div/mod pair and saves both so only one div.
 | 
|---|
| 306 |         signed char ceiling( signed char n, signed char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 307 |         unsigned char ceiling( unsigned char n, unsigned char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 308 |         short int ceiling( short int n, short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 309 |         unsigned short int ceiling( unsigned short int n, unsigned short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 310 |         int ceiling( int n, int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 311 |         unsigned int ceiling( unsigned int n, unsigned int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 312 |         long int ceiling( long int n, long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 313 |         unsigned long int ceiling( unsigned long int n, unsigned long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0) , align); }
 | 
|---|
| 314 |         long long int ceiling( long long int n, long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 315 |         unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
 | 
|---|
| 316 | 
 | 
|---|
| 317 |         // forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )
 | 
|---|
| 318 |         // T ceiling( T n, T align ) { return return floor( n + (n % align != 0 ? align - 1 : 0), align ); *}
 | 
|---|
| 319 | 
 | 
|---|
| 320 |         float floor( float x ) { return floorf( x ); }
 | 
|---|
| 321 |         // extern "C" { double floor( double ); }
 | 
|---|
| 322 |         long double floor( long double x ) { return floorl( x ); }
 | 
|---|
| 323 | 
 | 
|---|
| 324 |         float ceil( float x ) { return ceilf( x ); }
 | 
|---|
| 325 |         // extern "C" { double ceil( double ); }
 | 
|---|
| 326 |         long double ceil( long double x ) { return ceill( x ); }
 | 
|---|
| 327 | 
 | 
|---|
| 328 |         float trunc( float x ) { return truncf( x ); }
 | 
|---|
| 329 |         // extern "C" { double trunc( double ); }
 | 
|---|
| 330 |         long double trunc( long double x ) { return truncl( x ); }
 | 
|---|
| 331 | 
 | 
|---|
| 332 |         float rint( float x ) { return rintf( x ); }
 | 
|---|
| 333 |         // extern "C" { double rint( double x ); }
 | 
|---|
| 334 |         long double rint( long double x ) { return rintl( x ); }
 | 
|---|
| 335 |         long int rint( float x ) { return lrintf( x ); }
 | 
|---|
| 336 |         long int rint( double x ) { return lrint( x ); }
 | 
|---|
| 337 |         long int rint( long double x ) { return lrintl( x ); }
 | 
|---|
| 338 |         long long int rint( float x ) { return llrintf( x ); }
 | 
|---|
| 339 |         long long int rint( double x ) { return llrint( x ); }
 | 
|---|
| 340 |         long long int rint( long double x ) { return llrintl( x ); }
 | 
|---|
| 341 | 
 | 
|---|
| 342 |         long int lrint( float x ) { return lrintf( x ); }
 | 
|---|
| 343 |         // extern "C" { long int lrint( double ); }
 | 
|---|
| 344 |         long int lrint( long double x ) { return lrintl( x ); }
 | 
|---|
| 345 |         long long int llrint( float x ) { return llrintf( x ); }
 | 
|---|
| 346 |         // extern "C" { long long int llrint( double ); }
 | 
|---|
| 347 |         long long int llrint( long double x ) { return llrintl( x ); }
 | 
|---|
| 348 | 
 | 
|---|
| 349 |         float nearbyint( float x ) { return nearbyintf( x ); }
 | 
|---|
| 350 |         // extern "C" { double nearbyint( double ); }
 | 
|---|
| 351 |         long double nearbyint( long double x ) { return nearbyintl( x ); }
 | 
|---|
| 352 | 
 | 
|---|
| 353 |         float round( float x ) { return roundf( x ); }
 | 
|---|
| 354 |         // extern "C" { double round( double x ); }
 | 
|---|
| 355 |         long double round( long double x ) { return roundl( x ); }
 | 
|---|
| 356 |         long int round( float x ) { return lroundf( x ); }
 | 
|---|
| 357 |         long int round( double x ) { return lround( x ); }
 | 
|---|
| 358 |         long int round( long double x ) { return lroundl( x ); }
 | 
|---|
| 359 |         long long int round( float x ) { return llroundf( x ); }
 | 
|---|
| 360 |         long long int round( double x ) { return llround( x ); }
 | 
|---|
| 361 |         long long int round( long double x ) { return llroundl( x ); }
 | 
|---|
| 362 | 
 | 
|---|
| 363 |         long int lround( float x ) { return lroundf( x ); }
 | 
|---|
| 364 |         // extern "C" { long int lround( double ); }
 | 
|---|
| 365 |         long int lround( long double x ) { return lroundl( x ); }
 | 
|---|
| 366 |         long long int llround( float x ) { return llroundf( x ); }
 | 
|---|
| 367 |         // extern "C" { long long int llround( double ); }
 | 
|---|
| 368 |         long long int llround( long double x ) { return llroundl( x ); }
 | 
|---|
| 369 | } // distribution
 | 
|---|
| 370 | 
 | 
|---|
| 371 | //---------------------- Manipulation ----------------------
 | 
|---|
| 372 | 
 | 
|---|
| 373 | static inline {
 | 
|---|
| 374 |         float copysign( float x, float y ) { return copysignf( x, y ); }
 | 
|---|
| 375 |         // extern "C" { double copysign( double, double ); }
 | 
|---|
| 376 |         long double copysign( long double x, long double y ) { return copysignl( x, y ); }
 | 
|---|
| 377 | 
 | 
|---|
| 378 |         float frexp( float x, int * ip ) { return frexpf( x, ip ); }
 | 
|---|
| 379 |         // extern "C" { double frexp( double, int * ); }
 | 
|---|
| 380 |         long double frexp( long double x, int * ip ) { return frexpl( x, ip ); }
 | 
|---|
| 381 | 
 | 
|---|
| 382 |         float ldexp( float x, int exp2 ) { return ldexpf( x, exp2 ); }
 | 
|---|
| 383 |         // extern "C" { double ldexp( double, int ); }
 | 
|---|
| 384 |         long double ldexp( long double x, int exp2 ) { return ldexpl( x, exp2 ); }
 | 
|---|
| 385 | 
 | 
|---|
| 386 |         [ float, float ] modf( float x ) { float i; x = modff( x, &i ); return [ i, x ]; }
 | 
|---|
| 387 |         float modf( float x, float * i ) { return modff( x, i ); }
 | 
|---|
| 388 |         [ double, double ] modf( double x ) { double i; x = modf( x, &i ); return [ i, x ]; }
 | 
|---|
| 389 |         // extern "C" { double modf( double, double * ); }
 | 
|---|
| 390 |         [ long double, long double ] modf( long double x ) { long double i; x = modfl( x, &i ); return [ i, x ]; }
 | 
|---|
| 391 |         long double modf( long double x, long double * i ) { return modfl( x, i ); }
 | 
|---|
| 392 | 
 | 
|---|
| 393 |         float nextafter( float x, float y ) { return nextafterf( x, y ); }
 | 
|---|
| 394 |         // extern "C" { double nextafter( double, double ); }
 | 
|---|
| 395 |         long double nextafter( long double x, long double y ) { return nextafterl( x, y ); }
 | 
|---|
| 396 | 
 | 
|---|
| 397 |         float nexttoward( float x, long double y ) { return nexttowardf( x, y ); }
 | 
|---|
| 398 |         // extern "C" { double nexttoward( double, long double ); }
 | 
|---|
| 399 |         long double nexttoward( long double x, long double y ) { return nexttowardl( x, y ); }
 | 
|---|
| 400 | 
 | 
|---|
| 401 |         float scalbn( float x, int exp ) { return scalbnf( x, exp ); }
 | 
|---|
| 402 |         // extern "C" { double scalbn( double, int ); }
 | 
|---|
| 403 |         long double scalbn( long double x, int exp ) { return scalbnl( x, exp ); }
 | 
|---|
| 404 |         float scalbn( float x, long int exp ) { return scalblnf( x, exp ); }
 | 
|---|
| 405 |         double scalbn( double x, long int exp ) { return scalbln( x, exp ); }
 | 
|---|
| 406 |         long double scalbn( long double x, long int exp ) { return scalblnl( x, exp ); }
 | 
|---|
| 407 | 
 | 
|---|
| 408 |         float scalbln( float x, long int exp ) { return scalblnf( x, exp ); }
 | 
|---|
| 409 |         // extern "C" { double scalbln( double, long int ); }
 | 
|---|
| 410 |         long double scalbln( long double x, long int exp ) { return scalblnl( x, exp ); }
 | 
|---|
| 411 | } // distribution
 | 
|---|
| 412 | 
 | 
|---|
| 413 | //---------------------------------------
 | 
|---|
| 414 | 
 | 
|---|
| 415 | static inline {
 | 
|---|
| 416 |         forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
 | 
|---|
| 417 |         T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; }
 | 
|---|
| 418 | 
 | 
|---|
| 419 |         forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
 | 
|---|
| 420 |         T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; }
 | 
|---|
| 421 | 
 | 
|---|
| 422 |         forall( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
 | 
|---|
| 423 |         T smoothstep( T edge0, T edge1, T x ) { T t = clamp( (x - edge0) / (edge1 - edge0), (T){0}, (T){1} ); return t * t * ((T){3} - (T){2} * t); }
 | 
|---|
| 424 | } // distribution
 | 
|---|
| 425 | 
 | 
|---|
| 426 | // Local Variables: //
 | 
|---|
| 427 | // mode: c //
 | 
|---|
| 428 | // tab-width: 4 //
 | 
|---|
| 429 | // End: //
 | 
|---|