// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // math -- // // Author : Peter A. Buhr // Created On : Mon Apr 18 23:37:04 2016 // Last Modified By : Peter A. Buhr // Last Modified On : Fri Jul 13 11:02:15 2018 // Update Count : 116 // #pragma once #include #include //---------------------- General ---------------------- static inline float ?%?( float x, float y ) { return fmodf( x, y ); } static inline float fmod( float x, float y ) { return fmodf( x, y ); } static inline double ?%?( double x, double y ) { return fmod( x, y ); } // extern "C" { double fmod( double, double ); } static inline long double ?%?( long double x, long double y ) { return fmodl( x, y ); } static inline long double fmod( long double x, long double y ) { return fmodl( x, y ); } static inline float remainder( float x, float y ) { return remainderf( x, y ); } // extern "C" { double remainder( double, double ); } static inline long double remainder( long double x, long double y ) { return remainderl( x, y ); } static inline float remquo( float x, float y, int * quo ) { return remquof( x, y, quo ); } // extern "C" { double remquo( double x, double y, int * quo ); } static inline long double remquo( long double x, long double y, int * quo ) { return remquol( x, y, quo ); } static inline [ int, float ] remquo( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; } static inline [ int, double ] remquo( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; } static inline [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; } static inline [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; } static inline [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; } static inline [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; } static inline float fma( float x, float y, float z ) { return fmaf( x, y, z ); } // extern "C" { double fma( double, double, double ); } static inline long double fma( long double x, long double y, long double z ) { return fmal( x, y, z ); } static inline float fdim( float x, float y ) { return fdimf( x, y ); } // extern "C" { double fdim( double, double ); } static inline long double fdim( long double x, long double y ) { return fdiml( x, y ); } static inline float nan( const char * tag ) { return nanf( tag ); } // extern "C" { double nan( const char * ); } static inline long double nan( const char * tag ) { return nanl( tag ); } //---------------------- Exponential ---------------------- static inline float exp( float x ) { return expf( x ); } // extern "C" { double exp( double ); } static inline long double exp( long double x ) { return expl( x ); } static inline float _Complex exp( float _Complex x ) { return cexpf( x ); } static inline double _Complex exp( double _Complex x ) { return cexp( x ); } static inline long double _Complex exp( long double _Complex x ) { return cexpl( x ); } static inline float exp2( float x ) { return exp2f( x ); } // extern "C" { double exp2( double ); } static inline long double exp2( long double x ) { return exp2l( x ); } //static inline float _Complex exp2( float _Complex x ) { return cexp2f( x ); } //static inline double _Complex exp2( double _Complex x ) { return cexp2( x ); } //static inline long double _Complex exp2( long double _Complex x ) { return cexp2l( x ); } static inline float expm1( float x ) { return expm1f( x ); } // extern "C" { double expm1( double ); } static inline long double expm1( long double x ) { return expm1l( x ); } static inline float pow( float x, float y ) { return powf( x, y ); } // extern "C" { double pow( double, double ); } static inline long double pow( long double x, long double y ) { return powl( x, y ); } static inline float _Complex pow( float _Complex x, float _Complex y ) { return cpowf( x, y ); } static inline double _Complex pow( double _Complex x, double _Complex y ) { return cpow( x, y ); } static inline long double _Complex pow( long double _Complex x, long double _Complex y ) { return cpowl( x, y ); } //---------------------- Logarithm ---------------------- static inline float log( float x ) { return logf( x ); } // extern "C" { double log( double ); } static inline long double log( long double x ) { return logl( x ); } static inline float _Complex log( float _Complex x ) { return clogf( x ); } static inline double _Complex log( double _Complex x ) { return clog( x ); } static inline long double _Complex log( long double _Complex x ) { return clogl( x ); } static inline float log2( float x ) { return log2f( x ); } // extern "C" { double log2( double ); } static inline long double log2( long double x ) { return log2l( x ); } // static inline float _Complex log2( float _Complex x ) { return clog2f( x ); } // static inline double _Complex log2( double _Complex x ) { return clog2( x ); } // static inline long double _Complex log2( long double _Complex x ) { return clog2l( x ); } static inline float log10( float x ) { return log10f( x ); } // extern "C" { double log10( double ); } static inline long double log10( long double x ) { return log10l( x ); } // static inline float _Complex log10( float _Complex x ) { return clog10f( x ); } // static inline double _Complex log10( double _Complex x ) { return clog10( x ); } // static inline long double _Complex log10( long double _Complex x ) { return clog10l( x ); } static inline float log1p( float x ) { return log1pf( x ); } // extern "C" { double log1p( double ); } static inline long double log1p( long double x ) { return log1pl( x ); } static inline int ilogb( float x ) { return ilogbf( x ); } // extern "C" { int ilogb( double ); } static inline int ilogb( long double x ) { return ilogbl( x ); } static inline float logb( float x ) { return logbf( x ); } // extern "C" { double logb( double ); } static inline long double logb( long double x ) { return logbl( x ); } static inline float sqrt( float x ) { return sqrtf( x ); } // extern "C" { double sqrt( double ); } static inline long double sqrt( long double x ) { return sqrtl( x ); } static inline float _Complex sqrt( float _Complex x ) { return csqrtf( x ); } static inline double _Complex sqrt( double _Complex x ) { return csqrt( x ); } static inline long double _Complex sqrt( long double _Complex x ) { return csqrtl( x ); } static inline float cbrt( float x ) { return cbrtf( x ); } // extern "C" { double cbrt( double ); } static inline long double cbrt( long double x ) { return cbrtl( x ); } static inline float hypot( float x, float y ) { return hypotf( x, y ); } // extern "C" { double hypot( double, double ); } static inline long double hypot( long double x, long double y ) { return hypotl( x, y ); } //---------------------- Trigonometric ---------------------- static inline float sin( float x ) { return sinf( x ); } // extern "C" { double sin( double ); } static inline long double sin( long double x ) { return sinl( x ); } static inline float _Complex sin( float _Complex x ) { return csinf( x ); } static inline double _Complex sin( double _Complex x ) { return csin( x ); } static inline long double _Complex sin( long double _Complex x ) { return csinl( x ); } static inline float cos( float x ) { return cosf( x ); } // extern "C" { double cos( double ); } static inline long double cos( long double x ) { return cosl( x ); } static inline float _Complex cos( float _Complex x ) { return ccosf( x ); } static inline double _Complex cos( double _Complex x ) { return ccos( x ); } static inline long double _Complex cos( long double _Complex x ) { return ccosl( x ); } static inline float tan( float x ) { return tanf( x ); } // extern "C" { double tan( double ); } static inline long double tan( long double x ) { return tanl( x ); } static inline float _Complex tan( float _Complex x ) { return ctanf( x ); } static inline double _Complex tan( double _Complex x ) { return ctan( x ); } static inline long double _Complex tan( long double _Complex x ) { return ctanl( x ); } static inline float asin( float x ) { return asinf( x ); } // extern "C" { double asin( double ); } static inline long double asin( long double x ) { return asinl( x ); } static inline float _Complex asin( float _Complex x ) { return casinf( x ); } static inline double _Complex asin( double _Complex x ) { return casin( x ); } static inline long double _Complex asin( long double _Complex x ) { return casinl( x ); } static inline float acos( float x ) { return acosf( x ); } // extern "C" { double acos( double ); } static inline long double acos( long double x ) { return acosl( x ); } static inline float _Complex acos( float _Complex x ) { return cacosf( x ); } static inline double _Complex acos( double _Complex x ) { return cacos( x ); } static inline long double _Complex acos( long double _Complex x ) { return cacosl( x ); } static inline float atan( float x ) { return atanf( x ); } // extern "C" { double atan( double ); } static inline long double atan( long double x ) { return atanl( x ); } static inline float _Complex atan( float _Complex x ) { return catanf( x ); } static inline double _Complex atan( double _Complex x ) { return catan( x ); } static inline long double _Complex atan( long double _Complex x ) { return catanl( x ); } static inline float atan2( float x, float y ) { return atan2f( x, y ); } // extern "C" { double atan2( double, double ); } static inline long double atan2( long double x, long double y ) { return atan2l( x, y ); } // alternative name for atan2 static inline float atan( float x, float y ) { return atan2f( x, y ); } static inline double atan( double x, double y ) { return atan2( x, y ); } static inline long double atan( long double x, long double y ) { return atan2l( x, y ); } //---------------------- Hyperbolic ---------------------- static inline float sinh( float x ) { return sinhf( x ); } // extern "C" { double sinh( double ); } static inline long double sinh( long double x ) { return sinhl( x ); } static inline float _Complex sinh( float _Complex x ) { return csinhf( x ); } static inline double _Complex sinh( double _Complex x ) { return csinh( x ); } static inline long double _Complex sinh( long double _Complex x ) { return csinhl( x ); } static inline float cosh( float x ) { return coshf( x ); } // extern "C" { double cosh( double ); } static inline long double cosh( long double x ) { return coshl( x ); } static inline float _Complex cosh( float _Complex x ) { return ccoshf( x ); } static inline double _Complex cosh( double _Complex x ) { return ccosh( x ); } static inline long double _Complex cosh( long double _Complex x ) { return ccoshl( x ); } static inline float tanh( float x ) { return tanhf( x ); } // extern "C" { double tanh( double ); } static inline long double tanh( long double x ) { return tanhl( x ); } static inline float _Complex tanh( float _Complex x ) { return ctanhf( x ); } static inline double _Complex tanh( double _Complex x ) { return ctanh( x ); } static inline long double _Complex tanh( long double _Complex x ) { return ctanhl( x ); } static inline float asinh( float x ) { return asinhf( x ); } // extern "C" { double asinh( double ); } static inline long double asinh( long double x ) { return asinhl( x ); } static inline float _Complex asinh( float _Complex x ) { return casinhf( x ); } static inline double _Complex asinh( double _Complex x ) { return casinh( x ); } static inline long double _Complex asinh( long double _Complex x ) { return casinhl( x ); } static inline float acosh( float x ) { return acoshf( x ); } // extern "C" { double acosh( double ); } static inline long double acosh( long double x ) { return acoshl( x ); } static inline float _Complex acosh( float _Complex x ) { return cacoshf( x ); } static inline double _Complex acosh( double _Complex x ) { return cacosh( x ); } static inline long double _Complex acosh( long double _Complex x ) { return cacoshl( x ); } static inline float atanh( float x ) { return atanhf( x ); } // extern "C" { double atanh( double ); } static inline long double atanh( long double x ) { return atanhl( x ); } static inline float _Complex atanh( float _Complex x ) { return catanhf( x ); } static inline double _Complex atanh( double _Complex x ) { return catanh( x ); } static inline long double _Complex atanh( long double _Complex x ) { return catanhl( x ); } //---------------------- Error / Gamma ---------------------- static inline float erf( float x ) { return erff( x ); } // extern "C" { double erf( double ); } static inline long double erf( long double x ) { return erfl( x ); } // float _Complex erf( float _Complex ); // double _Complex erf( double _Complex ); // long double _Complex erf( long double _Complex ); static inline float erfc( float x ) { return erfcf( x ); } // extern "C" { double erfc( double ); } static inline long double erfc( long double x ) { return erfcl( x ); } // float _Complex erfc( float _Complex ); // double _Complex erfc( double _Complex ); // long double _Complex erfc( long double _Complex ); static inline float lgamma( float x ) { return lgammaf( x ); } // extern "C" { double lgamma( double ); } static inline long double lgamma( long double x ) { return lgammal( x ); } static inline float lgamma( float x, int * sign ) { return lgammaf_r( x, sign ); } static inline double lgamma( double x, int * sign ) { return lgamma_r( x, sign ); } static inline long double lgamma( long double x, int * sign ) { return lgammal_r( x, sign ); } static inline float tgamma( float x ) { return tgammaf( x ); } // extern "C" { double tgamma( double ); } static inline long double tgamma( long double x ) { return tgammal( x ); } //---------------------- Nearest Integer ---------------------- static inline float floor( float x ) { return floorf( x ); } // extern "C" { double floor( double ); } static inline long double floor( long double x ) { return floorl( x ); } static inline float ceil( float x ) { return ceilf( x ); } // extern "C" { double ceil( double ); } static inline long double ceil( long double x ) { return ceill( x ); } static inline float trunc( float x ) { return truncf( x ); } // extern "C" { double trunc( double ); } static inline long double trunc( long double x ) { return truncl( x ); } static inline float rint( float x ) { return rintf( x ); } // extern "C" { double rint( double x ); } static inline long double rint( long double x ) { return rintl( x ); } static inline long int rint( float x ) { return lrintf( x ); } static inline long int rint( double x ) { return lrint( x ); } static inline long int rint( long double x ) { return lrintl( x ); } static inline long long int rint( float x ) { return llrintf( x ); } static inline long long int rint( double x ) { return llrint( x ); } static inline long long int rint( long double x ) { return llrintl( x ); } static inline long int lrint( float x ) { return lrintf( x ); } // extern "C" { long int lrint( double ); } static inline long int lrint( long double x ) { return lrintl( x ); } static inline long long int llrint( float x ) { return llrintf( x ); } // extern "C" { long long int llrint( double ); } static inline long long int llrint( long double x ) { return llrintl( x ); } static inline float nearbyint( float x ) { return nearbyintf( x ); } // extern "C" { double nearbyint( double ); } static inline long double nearbyint( long double x ) { return nearbyintl( x ); } static inline float round( float x ) { return roundf( x ); } // extern "C" { double round( double x ); } static inline long double round( long double x ) { return roundl( x ); } static inline long int round( float x ) { return lroundf( x ); } static inline long int round( double x ) { return lround( x ); } static inline long int round( long double x ) { return lroundl( x ); } static inline long long int round( float x ) { return llroundf( x ); } static inline long long int round( double x ) { return llround( x ); } static inline long long int round( long double x ) { return llroundl( x ); } static inline long int lround( float x ) { return lroundf( x ); } // extern "C" { long int lround( double ); } static inline long int lround( long double x ) { return lroundl( x ); } static inline long long int llround( float x ) { return llroundf( x ); } // extern "C" { long long int llround( double ); } static inline long long int llround( long double x ) { return llroundl( x ); } //---------------------- Manipulation ---------------------- static inline float copysign( float x, float y ) { return copysignf( x, y ); } // extern "C" { double copysign( double, double ); } static inline long double copysign( long double x, long double y ) { return copysignl( x, y ); } static inline float frexp( float x, int * ip ) { return frexpf( x, ip ); } // extern "C" { double frexp( double, int * ); } static inline long double frexp( long double x, int * ip ) { return frexpl( x, ip ); } static inline float ldexp( float x, int exp2 ) { return ldexpf( x, exp2 ); } // extern "C" { double ldexp( double, int ); } static inline long double ldexp( long double x, int exp2 ) { return ldexpl( x, exp2 ); } static inline [ float, float ] modf( float x ) { float i; x = modff( x, &i ); return [ i, x ]; } static inline float modf( float x, float * i ) { return modff( x, i ); } static inline [ double, double ] modf( double x ) { double i; x = modf( x, &i ); return [ i, x ]; } // extern "C" { double modf( double, double * ); } static inline [ long double, long double ] modf( long double x ) { long double i; x = modfl( x, &i ); return [ i, x ]; } static inline long double modf( long double x, long double * i ) { return modfl( x, i ); } static inline float nextafter( float x, float y ) { return nextafterf( x, y ); } // extern "C" { double nextafter( double, double ); } static inline long double nextafter( long double x, long double y ) { return nextafterl( x, y ); } static inline float nexttoward( float x, long double y ) { return nexttowardf( x, y ); } // extern "C" { double nexttoward( double, long double ); } static inline long double nexttoward( long double x, long double y ) { return nexttowardl( x, y ); } static inline float scalbn( float x, int exp ) { return scalbnf( x, exp ); } // extern "C" { double scalbn( double, int ); } static inline long double scalbn( long double x, int exp ) { return scalbnl( x, exp ); } static inline float scalbn( float x, long int exp ) { return scalblnf( x, exp ); } static inline double scalbn( double x, long int exp ) { return scalbln( x, exp ); } static inline long double scalbn( long double x, long int exp ) { return scalblnl( x, exp ); } static inline float scalbln( float x, long int exp ) { return scalblnf( x, exp ); } // extern "C" { double scalbln( double, long int ); } static inline long double scalbln( long double x, long int exp ) { return scalblnl( x, exp ); } //--------------------------------------- #include "common" //--------------------------------------- forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } ) T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; } forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?