/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ float atanhf(float x) { union {float f; uint32_t i;} u = {.f = x}; unsigned s = u.i >> 31; float_t y; /* |x| */ u.i &= 0x7fffffff; y = u.f; if (u.i < 0x3f800000 - (1<<23)) { if (u.i < 0x3f800000 - (32<<23)) { /* handle underflow */ if (u.i < (1<<23)) FORCE_EVAL((float)(y*y)); } else { /* |x| < 0.5, up to 1.7ulp error */ y = 0.5f*log1pf(2*y + 2*y*y/(1-y)); } } else { /* avoid overflow */ y = 0.5f*log1pf(2*(y/(1-y))); } return s ? -y : y; }
static inline void do_hard_work(float x, float y, float *rx, int *B_is_usable, float *B, float *sqrt_A2my2, float *new_y) { float R, S, A; float Am1, Amy; R = hypotf(x, y + 1); S = hypotf(x, y - 1); A = (R + S) / 2; if (A < 1) A = 1; if (A < A_crossover) { if (y == 1 && x < FLT_EPSILON * FLT_EPSILON / 128) { *rx = sqrtf(x); } else if (x >= FLT_EPSILON * fabsf(y - 1)) { Am1 = f(x, 1 + y, R) + f(x, 1 - y, S); *rx = log1pf(Am1 + sqrtf(Am1 * (A + 1))); } else if (y < 1) { *rx = x / sqrtf((1 - y) * (1 + y)); } else { *rx = log1pf((y - 1) + sqrtf((y - 1) * (y + 1))); } } else { *rx = logf(A + sqrtf(A * A - 1)); } *new_y = y; if (y < FOUR_SQRT_MIN) { *B_is_usable = 0; *sqrt_A2my2 = A * (2 / FLT_EPSILON); *new_y = y * (2 / FLT_EPSILON); return; } *B = y / A; *B_is_usable = 1; if (*B > B_crossover) { *B_is_usable = 0; if (y == 1 && x < FLT_EPSILON / 128) { *sqrt_A2my2 = sqrtf(x) * sqrtf((A + y) / 2); } else if (x >= FLT_EPSILON * fabsf(y - 1)) { Amy = f(x, y + 1, R) + f(x, y - 1, S); *sqrt_A2my2 = sqrtf(Amy * (A + y)); } else if (y > 1) { *sqrt_A2my2 = x * (4 / FLT_EPSILON / FLT_EPSILON) * y / sqrtf((y + 1) * (y - 1)); *new_y = y * (4 / FLT_EPSILON / FLT_EPSILON); } else { *sqrt_A2my2 = sqrtf((1 - y) * (1 + y)); } } }
void test_log1p() { static_assert((std::is_same<decltype(log1p((double)0)), double>::value), ""); static_assert((std::is_same<decltype(log1pf(0)), float>::value), ""); static_assert((std::is_same<decltype(log1pl(0)), long double>::value), ""); assert(log1p(0) == 0); }
static TACommandVerdict log1pf_cmd(TAThread thread,TAInputStream stream) { float x, res; // Prepare x = readFloat(&stream); errno = 0; START_TARGET_OPERATION(thread); // Execute res = log1pf(x); END_TARGET_OPERATION(thread); // Response writeFloat(thread, res); writeInt(thread, errno); sendResponse(thread); return taDefaultVerdict; }
float asinhf(float x) { float t,w; int32_t hx,ix; GET_FLOAT_WORD(hx, x); ix = hx & 0x7fffffff; if (ix >= 0x7f800000) /* x is inf or NaN */ return x+x; if (ix < 0x31800000) { /* |x| < 2**-28 */ /* return x inexact except 0 */ if (huge+x > 1.0f) return x; } if (ix > 0x4d800000) { /* |x| > 2**28 */ w = logf(fabsf(x)) + ln2; } else if (ix > 0x40000000) { /* 2**28 > |x| > 2.0 */ t = fabsf(x); w = logf(2.0f*t + 1.0f/(sqrtf(x*x+1.0f)+t)); } else { /* 2.0 > |x| > 2**-28 */ t = x*x; w =log1pf(fabsf(x) + t/(1.0f+sqrtf(1.0f+t))); } if (hx > 0) return w; return -w; }
inline float operator()(const float &x) const { #if defined(NTA_OS_WINDOWS) return (float)log(1.0 + x); #else return log1pf(x); #endif }
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ float asinhf(float x) { union { float f; uint32_t i; } u = {.f = x}; uint32_t i = u.i & 0x7fffffff; unsigned s = u.i >> 31; /* |x| */ u.i = i; x = u.f; if (i >= 0x3f800000 + (12 << 23)) { /* |x| >= 0x1p12 or inf or nan */ x = logf(x) + 0.693147180559945309417232121458176568f; } else if (i >= 0x3f800000 + (1 << 23)) { /* |x| >= 2 */ x = logf(2 * x + 1 / (sqrtf(x * x + 1) + x)); } else if (i >= 0x3f800000 - (12 << 23)) { /* |x| >= 0x1p-12, up to 1.6ulp error in [0.125,0.5] */ x = log1pf(x + x * x / (sqrtf(x * x + 1) + 1)); } else { /* |x| < 0x1p-12, raise inexact if x!=0 */ FORCE_EVAL(x + 0x1p120f); } return s ? -x : x; }
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ float atanhf(float x) { union {float f; uint32_t i;} u = {.f = x}; unsigned s = u.i >> 31; /* |x| */ u.i &= 0x7fffffff; x = u.f; if (u.i < 0x3f800000 - (1<<23)) { /* |x| < 0.5, up to 1.7ulp error */ x = 0.5f*log1pf(2*x + 2*x*x/(1-x)); } else { x = 0.5f*log1pf(2*x/(1-x)); } return s ? -x : x; }
void OpenVML_FUNCNAME_REF(vsLog1p)(const VML_INT n, const float * a, float * y){ VML_INT i; if (n<=0) return; if (a==NULL || y==NULL) return; for(i=0; i<n; i++){ y[i]=log1pf(a[i]); } }
float atanhf(float x) { float t; int32_t hx,ix; GET_FLOAT_WORD(hx,x); ix = hx&0x7fffffff; if (ix>0x3f800000) /* |x|>1 */ return (x-x)/(x-x); if(ix==0x3f800000) return x/zero; if(ix<0x31800000&&(huge+x)>zero) return x; /* x<2**-28 */ SET_FLOAT_WORD(x,ix); if(ix<0x3f000000) { /* x < 0.5 */ t = x+x; t = (float)0.5*log1pf(t+t*x/(one-x)); } else t = (float)0.5*log1pf((x+x)/(one-x)); if(hx>=0) return t; else return -t; }
/* acosh(x) = log(x + sqrt(x*x-1)) */ float acoshf(float x) { union {float f; uint32_t i;} u = {x}; uint32_t a = u.i & 0x7fffffff; if (a < 0x3f800000+(1<<23)) /* |x| < 2, invalid if x < 1 or nan */ /* up to 2ulp error in [1,1.125] */ return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1))); if (a < 0x3f800000+(12<<23)) /* |x| < 0x1p12 */ return logf(2*x - 1/(x+sqrtf(x*x-1))); /* x >= 0x1p12 */ return logf(x) + 0.693147180559945309417232121458176568f; }
float complex catanhf(float complex z) { float x, y, ax, ay, rx, ry; x = crealf(z); y = cimagf(z); ax = fabsf(x); ay = fabsf(y); if (y == 0 && ax <= 1) return (CMPLXF(atanhf(x), y)); if (x == 0) return (CMPLXF(x, atanf(y))); if (isnan(x) || isnan(y)) { if (isinf(x)) return (CMPLXF(copysignf(0, x), y + y)); if (isinf(y)) return (CMPLXF(copysignf(0, x), copysignf(pio2_hi + pio2_lo, y))); return (CMPLXF(x + 0.0L + (y + 0), x + 0.0L + (y + 0))); } if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) return (CMPLXF(real_part_reciprocal(x, y), copysignf(pio2_hi + pio2_lo, y))); if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) { raise_inexact(); return (z); } if (ax == 1 && ay < FLT_EPSILON) rx = (m_ln2 - logf(ay)) / 2; else rx = log1pf(4 * ax / sum_squares(ax - 1, ay)) / 4; if (ax == 1) ry = atan2f(2, -ay) / 2; else if (ay < FLT_EPSILON) ry = atan2f(2 * ay, (1 - ax) * (1 + ax)) / 2; else ry = atan2f(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2; return (CMPLXF(copysignf(rx, x), copysignf(ry, y))); }
//------------------------------------------------------------------------------ float Cmath::__ieee754_acoshf( float x ) { static const float one = 1.0; static const float ln2 = 6.9314718246e-01; // 0x3f317218 float t; Cmp_signed__int32 hx; get_float_word( hx, x ); if( hx < 0x3f800000 ) { // x < 1 return ( x - x ) / ( x - x ); } else if( hx >= 0x4d800000 ) { // x > 2**28 if( !uword_isfinite( hx ) ) { // x is inf of NaN return x + x; } else { return __ieee754_logf( x ) + ln2; // acosh(huge)=log(2x) } } else if ( hx == 0x3f800000 ) { return 0.0; // acosh(1) = 0 } else if ( hx > 0x40000000 ) { // 2**28 > x > 2 t = x * x; return __ieee754_logf( (float)2.0 * x - one / ( x + __ieee754_sqrtf( t - one ) ) ); } else { // 1<x<2 t = x - one; return log1pf( t + __ieee754_sqrtf( (float)2.0 * t + t * t ) ); } }
float asinhf(float x) { float t,w; int32_t hx,ix; GET_FLOAT_WORD(hx,x); ix = hx&0x7fffffff; if(ix>=0x7f800000) return x+x; /* x is inf or NaN */ if(ix< 0x31800000) { /* |x|<2**-28 */ if(huge+x>one) return x; /* return x inexact except 0 */ } if(ix>0x4d800000) { /* |x| > 2**28 */ w = __ieee754_logf(fabsf(x))+ln2; } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ t = fabsf(x); w = __ieee754_logf((float)2.0*t+one/(__ieee754_sqrtf(x*x+one)+t)); } else { /* 2.0 > |x| > 2**-28 */ t = x*x; w =log1pf(fabsf(x)+t/(one+__ieee754_sqrtf(one+t))); } if(hx>0) return w; else return -w; }
float __ieee754_acoshf(float x) { float t; int32_t hx; GET_FLOAT_WORD(hx,x); if(hx<0x3f800000) { /* x < 1 */ return (x-x)/(x-x); } else if(hx >=0x4d800000) { /* x > 2**28 */ if(hx >=0x7f800000) { /* x is inf of NaN */ return x+x; } else return __ieee754_logf(x)+ln2; /* acosh(huge)=log(2x) */ } else if (hx==0x3f800000) { return 0.0; /* acosh(1) = 0 */ } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ t=x*x; return __ieee754_logf((float)2.0*x-one/(x+__ieee754_sqrtf(t-one))); } else { /* 1<x<2 */ t = x-one; return log1pf(t+__ieee754_sqrtf((float)2.0*t+t*t)); } }
inline float log1pf2(float x) { return log1pf(x); }
__host__ void single_precision_math_functions() { int iX; float fX, fY; acosf(1.0f); acoshf(1.0f); asinf(0.0f); asinhf(0.0f); atan2f(0.0f, 1.0f); atanf(0.0f); atanhf(0.0f); cbrtf(0.0f); ceilf(0.0f); copysignf(1.0f, -2.0f); cosf(0.0f); coshf(0.0f); //cospif(0.0f); //cyl_bessel_i0f(0.0f); //cyl_bessel_i1f(0.0f); erfcf(0.0f); //erfcinvf(2.0f); //erfcxf(0.0f); erff(0.0f); //erfinvf(1.0f); exp10f(0.0f); exp2f(0.0f); expf(0.0f); expm1f(0.0f); fabsf(1.0f); fdimf(1.0f, 0.0f); //fdividef(0.0f, 1.0f); floorf(0.0f); fmaf(1.0f, 2.0f, 3.0f); fmaxf(0.0f, 0.0f); fminf(0.0f, 0.0f); fmodf(0.0f, 1.0f); frexpf(0.0f, &iX); hypotf(1.0f, 0.0f); ilogbf(1.0f); isfinite(0.0f); isinf(0.0f); isnan(0.0f); ///j0f(0.0f); ///j1f(0.0f); ///jnf(-1.0f, 1.0f); ldexpf(0.0f, 0); ///lgammaf(1.0f); ///llrintf(0.0f); ///llroundf(0.0f); log10f(1.0f); log1pf(-1.0f); log2f(1.0f); logbf(1.0f); logf(1.0f); ///lrintf(0.0f); ///lroundf(0.0f); modff(0.0f, &fX); ///nanf("1"); nearbyintf(0.0f); //nextafterf(0.0f); //norm3df(1.0f, 0.0f, 0.0f); //norm4df(1.0f, 0.0f, 0.0f, 0.0f); //normcdff(0.0f); //normcdfinvf(1.0f); //fX = 1.0f; normf(1, &fX); powf(1.0f, 0.0f); //rcbrtf(1.0f); remainderf(2.0f, 1.0f); remquof(1.0f, 2.0f, &iX); //rhypotf(0.0f, 1.0f); ///rintf(1.0f); //rnorm3df(0.0f, 0.0f, 1.0f); //rnorm4df(0.0f, 0.0f, 0.0f, 1.0f); //fX = 1.0f; rnormf(1, &fX); roundf(0.0f); //rsqrtf(1.0f); ///scalblnf(0.0f, 1); scalbnf(0.0f, 1); signbit(1.0f); sincosf(0.0f, &fX, &fY); //sincospif(0.0f, &fX, &fY); sinf(0.0f); sinhf(0.0f); //sinpif(0.0f); sqrtf(0.0f); tanf(0.0f); tanhf(0.0f); tgammaf(2.0f); truncf(0.0f); ///y0f(1.0f); ///y1f(1.0f); ///ynf(1, 1.0f); }
JNIEXPORT void JNICALL Java_com_lightcrafts_jai_opimage_ColorSelectionMaskOpImage_nativeUshortLoop (JNIEnv *env, jobject cls, jshortArray jsrcData, jbyteArray jdstData, jint width, jint height, jintArray jsrcBandOffsets, jint dstOffset, jint srcLineStride, jint dstLineStride, jfloatArray jcolorSelection, jfloat wr, jfloat wg, jfloat wb) { ushort *srcData = (ushort *) env->GetPrimitiveArrayCritical(jsrcData, 0); byte *dstData = (byte *) env->GetPrimitiveArrayCritical(jdstData, 0); int *srcBandOffsets = (int *) env->GetPrimitiveArrayCritical(jsrcBandOffsets, 0); float *colorSelection = (float *) env->GetPrimitiveArrayCritical(jcolorSelection, 0); int srcROffset = srcBandOffsets[0]; int srcGOffset = srcBandOffsets[1]; int srcBOffset = srcBandOffsets[2]; float hueLower = colorSelection[0]; float hueLowerFeather = colorSelection[1]; float hueUpper = colorSelection[2]; float hueUpperFeather = colorSelection[3]; float luminosityLower = colorSelection[4]; float luminosityLowerFeather = colorSelection[5]; float luminosityUpper = colorSelection[6]; float luminosityUpperFeather = colorSelection[7]; int hueOffset = 0; if (hueLower < 0 || hueLower - hueLowerFeather < 0 || hueUpper < 0) { hueLower += 1; hueUpper += 1; hueOffset = 1; } else if (hueLower > 1 || hueUpper + hueUpperFeather > 1 || hueUpper > 1) { hueOffset = -1; } for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { float r = srcData[3 * col + row * srcLineStride + srcROffset]; float g = srcData[3 * col + row * srcLineStride + srcGOffset]; float b = srcData[3 * col + row * srcLineStride + srcBOffset]; // float hue = hue(r / (float) 0xffff, g / (float) 0xffff, b / (float) 0xffff) / (float) (2 * Math.PI); float cmax = (r > g) ? r : g; if (b > cmax) cmax = b; float cmin = (r < g) ? r : g; if (b < cmin) cmin = b; float saturation; if (cmax != 0) saturation = (cmax - cmin) / cmax; else saturation = 0; #if defined(__ppc__) float luminosity = (float) (log1pf((wr * r + wg * g + wb * b)/0x100) / (8 * logf(2))); #else float luminosity = (float) (fast_log2((wr * r + wg * g + wb * b)/0x100) / 8); #endif float luminosityMask, colorMask; const float stmin = 0.01f; const float stmax = 0.02f; const float ltmin = .01; const float ltmax = .02; if (saturation > stmin && luminosity > ltmin) { float h = hue(r, g, b) / (float) (2 * M_PI); if (hueOffset == 1 && h < hueLower - hueLowerFeather) h += 1; else if (hueOffset == -1 && h < 0.5) h += 1; if (h >= hueLower && h <= hueUpper) colorMask = 1; else if (h >= (hueLower - hueLowerFeather) && h < hueLower) colorMask = (h - (hueLower - hueLowerFeather))/hueLowerFeather; else if (h > hueUpper && h <= (hueUpper + hueUpperFeather)) colorMask = (hueUpper + hueUpperFeather - h)/hueUpperFeather; else colorMask = 0; if (saturation < stmax) colorMask *= (saturation - stmin) / (stmax - stmin); if (luminosity < ltmax) colorMask *= (luminosity - ltmin) / (ltmax - ltmin); } else colorMask = 0; if (luminosity >= luminosityLower && luminosity <= luminosityUpper) luminosityMask = 1; else if (luminosity >= (luminosityLower - luminosityLowerFeather) && luminosity < luminosityLower) luminosityMask = (luminosity - (luminosityLower - luminosityLowerFeather))/luminosityLowerFeather; else if (luminosity > luminosityUpper && luminosity <= (luminosityUpper + luminosityUpperFeather)) luminosityMask = (luminosityUpper + luminosityUpperFeather - luminosity)/luminosityUpperFeather; else luminosityMask = 0; colorMask *= luminosityMask; dstData[col + row * dstLineStride + dstOffset] = (byte) (0xff * colorMask); } } env->ReleasePrimitiveArrayCritical(jsrcData, srcData, 0); env->ReleasePrimitiveArrayCritical(jdstData, dstData, 0); env->ReleasePrimitiveArrayCritical(jsrcBandOffsets, srcBandOffsets, 0); env->ReleasePrimitiveArrayCritical(jcolorSelection, colorSelection, 0); }
float logadd(float x, float y) { if (y <= x) return x + log1pf(expf(y - x)); else return y + log1pf(expf(x - y)); }
void domathf (void) { #ifndef NO_FLOAT float f1; float f2; int i1; f1 = acosf(0.0); fprintf( stdout, "acosf : %f\n", f1); f1 = acoshf(0.0); fprintf( stdout, "acoshf : %f\n", f1); f1 = asinf(1.0); fprintf( stdout, "asinf : %f\n", f1); f1 = asinhf(1.0); fprintf( stdout, "asinhf : %f\n", f1); f1 = atanf(M_PI_4); fprintf( stdout, "atanf : %f\n", f1); f1 = atan2f(2.3, 2.3); fprintf( stdout, "atan2f : %f\n", f1); f1 = atanhf(1.0); fprintf( stdout, "atanhf : %f\n", f1); f1 = cbrtf(27.0); fprintf( stdout, "cbrtf : %f\n", f1); f1 = ceilf(3.5); fprintf( stdout, "ceilf : %f\n", f1); f1 = copysignf(3.5, -2.5); fprintf( stdout, "copysignf : %f\n", f1); f1 = cosf(M_PI_2); fprintf( stdout, "cosf : %f\n", f1); f1 = coshf(M_PI_2); fprintf( stdout, "coshf : %f\n", f1); f1 = erff(42.0); fprintf( stdout, "erff : %f\n", f1); f1 = erfcf(42.0); fprintf( stdout, "erfcf : %f\n", f1); f1 = expf(0.42); fprintf( stdout, "expf : %f\n", f1); f1 = exp2f(0.42); fprintf( stdout, "exp2f : %f\n", f1); f1 = expm1f(0.00042); fprintf( stdout, "expm1f : %f\n", f1); f1 = fabsf(-1.123); fprintf( stdout, "fabsf : %f\n", f1); f1 = fdimf(1.123, 2.123); fprintf( stdout, "fdimf : %f\n", f1); f1 = floorf(0.5); fprintf( stdout, "floorf : %f\n", f1); f1 = floorf(-0.5); fprintf( stdout, "floorf : %f\n", f1); f1 = fmaf(2.1, 2.2, 3.01); fprintf( stdout, "fmaf : %f\n", f1); f1 = fmaxf(-0.42, 0.42); fprintf( stdout, "fmaxf : %f\n", f1); f1 = fminf(-0.42, 0.42); fprintf( stdout, "fminf : %f\n", f1); f1 = fmodf(42.0, 3.0); fprintf( stdout, "fmodf : %f\n", f1); /* no type-specific variant */ i1 = fpclassify(1.0); fprintf( stdout, "fpclassify : %d\n", i1); f1 = frexpf(42.0, &i1); fprintf( stdout, "frexpf : %f\n", f1); f1 = hypotf(42.0, 42.0); fprintf( stdout, "hypotf : %f\n", f1); i1 = ilogbf(42.0); fprintf( stdout, "ilogbf : %d\n", i1); /* no type-specific variant */ i1 = isfinite(3.0); fprintf( stdout, "isfinite : %d\n", i1); /* no type-specific variant */ i1 = isgreater(3.0, 3.1); fprintf( stdout, "isgreater : %d\n", i1); /* no type-specific variant */ i1 = isgreaterequal(3.0, 3.1); fprintf( stdout, "isgreaterequal : %d\n", i1); /* no type-specific variant */ i1 = isinf(3.0); fprintf( stdout, "isinf : %d\n", i1); /* no type-specific variant */ i1 = isless(3.0, 3.1); fprintf( stdout, "isless : %d\n", i1); /* no type-specific variant */ i1 = islessequal(3.0, 3.1); fprintf( stdout, "islessequal : %d\n", i1); /* no type-specific variant */ i1 = islessgreater(3.0, 3.1); fprintf( stdout, "islessgreater : %d\n", i1); /* no type-specific variant */ i1 = isnan(0.0); fprintf( stdout, "isnan : %d\n", i1); /* no type-specific variant */ i1 = isnormal(3.0); fprintf( stdout, "isnormal : %d\n", i1); /* no type-specific variant */ f1 = isunordered(1.0, 2.0); fprintf( stdout, "isunordered : %d\n", i1); f1 = j0f(1.2); fprintf( stdout, "j0f : %f\n", f1); f1 = j1f(1.2); fprintf( stdout, "j1f : %f\n", f1); f1 = jnf(2,1.2); fprintf( stdout, "jnf : %f\n", f1); f1 = ldexpf(1.2,3); fprintf( stdout, "ldexpf : %f\n", f1); f1 = lgammaf(42.0); fprintf( stdout, "lgammaf : %f\n", f1); f1 = llrintf(-0.5); fprintf( stdout, "llrintf : %f\n", f1); f1 = llrintf(0.5); fprintf( stdout, "llrintf : %f\n", f1); f1 = llroundf(-0.5); fprintf( stdout, "lroundf : %f\n", f1); f1 = llroundf(0.5); fprintf( stdout, "lroundf : %f\n", f1); f1 = logf(42.0); fprintf( stdout, "logf : %f\n", f1); f1 = log10f(42.0); fprintf( stdout, "log10f : %f\n", f1); f1 = log1pf(42.0); fprintf( stdout, "log1pf : %f\n", f1); f1 = log2f(42.0); fprintf( stdout, "log2f : %f\n", f1); f1 = logbf(42.0); fprintf( stdout, "logbf : %f\n", f1); f1 = lrintf(-0.5); fprintf( stdout, "lrintf : %f\n", f1); f1 = lrintf(0.5); fprintf( stdout, "lrintf : %f\n", f1); f1 = lroundf(-0.5); fprintf( stdout, "lroundf : %f\n", f1); f1 = lroundf(0.5); fprintf( stdout, "lroundf : %f\n", f1); f1 = modff(42.0,&f2); fprintf( stdout, "lmodff : %f\n", f1); f1 = nanf(""); fprintf( stdout, "nanf : %f\n", f1); f1 = nearbyintf(1.5); fprintf( stdout, "nearbyintf : %f\n", f1); f1 = nextafterf(1.5,2.0); fprintf( stdout, "nextafterf : %f\n", f1); f1 = powf(3.01, 2.0); fprintf( stdout, "powf : %f\n", f1); f1 = remainderf(3.01,2.0); fprintf( stdout, "remainderf : %f\n", f1); f1 = remquof(29.0,3.0,&i1); fprintf( stdout, "remquof : %f\n", f1); f1 = rintf(0.5); fprintf( stdout, "rintf : %f\n", f1); f1 = rintf(-0.5); fprintf( stdout, "rintf : %f\n", f1); f1 = roundf(0.5); fprintf( stdout, "roundf : %f\n", f1); f1 = roundf(-0.5); fprintf( stdout, "roundf : %f\n", f1); f1 = scalblnf(1.2,3); fprintf( stdout, "scalblnf : %f\n", f1); f1 = scalbnf(1.2,3); fprintf( stdout, "scalbnf : %f\n", f1); /* no type-specific variant */ i1 = signbit(1.0); fprintf( stdout, "signbit : %i\n", i1); f1 = sinf(M_PI_4); fprintf( stdout, "sinf : %f\n", f1); f1 = sinhf(M_PI_4); fprintf( stdout, "sinhf : %f\n", f1); f1 = sqrtf(9.0); fprintf( stdout, "sqrtf : %f\n", f1); f1 = tanf(M_PI_4); fprintf( stdout, "tanf : %f\n", f1); f1 = tanhf(M_PI_4); fprintf( stdout, "tanhf : %f\n", f1); f1 = tgammaf(2.1); fprintf( stdout, "tgammaf : %f\n", f1); f1 = truncf(3.5); fprintf( stdout, "truncf : %f\n", f1); f1 = y0f(1.2); fprintf( stdout, "y0f : %f\n", f1); f1 = y1f(1.2); fprintf( stdout, "y1f : %f\n", f1); f1 = ynf(3,1.2); fprintf( stdout, "ynf : %f\n", f1); #endif }
static int testf(float float_x, long double long_double_x, /*float complex float_complex_x,*/ int int_x, long long_x) { int r = 0; r += acosf(float_x); r += acoshf(float_x); r += asinf(float_x); r += asinhf(float_x); r += atan2f(float_x, float_x); r += atanf(float_x); r += atanhf(float_x); /*r += cargf(float_complex_x); - will fight with complex numbers later */ r += cbrtf(float_x); r += ceilf(float_x); r += copysignf(float_x, float_x); r += cosf(float_x); r += coshf(float_x); r += erfcf(float_x); r += erff(float_x); r += exp2f(float_x); r += expf(float_x); r += expm1f(float_x); r += fabsf(float_x); r += fdimf(float_x, float_x); r += floorf(float_x); r += fmaf(float_x, float_x, float_x); r += fmaxf(float_x, float_x); r += fminf(float_x, float_x); r += fmodf(float_x, float_x); r += frexpf(float_x, &int_x); r += gammaf(float_x); r += hypotf(float_x, float_x); r += ilogbf(float_x); r += ldexpf(float_x, int_x); r += lgammaf(float_x); r += llrintf(float_x); r += llroundf(float_x); r += log10f(float_x); r += log1pf(float_x); r += log2f(float_x); r += logbf(float_x); r += logf(float_x); r += lrintf(float_x); r += lroundf(float_x); r += modff(float_x, &float_x); r += nearbyintf(float_x); r += nexttowardf(float_x, long_double_x); r += powf(float_x, float_x); r += remainderf(float_x, float_x); r += remquof(float_x, float_x, &int_x); r += rintf(float_x); r += roundf(float_x); #ifdef __UCLIBC_SUSV3_LEGACY__ r += scalbf(float_x, float_x); #endif r += scalblnf(float_x, long_x); r += scalbnf(float_x, int_x); r += significandf(float_x); r += sinf(float_x); r += sinhf(float_x); r += sqrtf(float_x); r += tanf(float_x); r += tanhf(float_x); r += tgammaf(float_x); r += truncf(float_x); return r; }
float testf (float __x) { return log1pf(1.0); }
TEST(math, log1pf) { ASSERT_EQ(-HUGE_VALF, log1pf(-1.0f)); ASSERT_TRUE(isnanf(log1pf(nanf("")))); ASSERT_TRUE(__isinff(log1pf(HUGE_VALF))); ASSERT_FLOAT_EQ(1.0f, log1pf(static_cast<float>(M_E) - 1.0f)); }
__global__ void FloatMathPrecise() { int iX; float fX, fY; acosf(1.0f); acoshf(1.0f); asinf(0.0f); asinhf(0.0f); atan2f(0.0f, 1.0f); atanf(0.0f); atanhf(0.0f); cbrtf(0.0f); fX = ceilf(0.0f); fX = copysignf(1.0f, -2.0f); cosf(0.0f); coshf(0.0f); cospif(0.0f); cyl_bessel_i0f(0.0f); cyl_bessel_i1f(0.0f); erfcf(0.0f); erfcinvf(2.0f); erfcxf(0.0f); erff(0.0f); erfinvf(1.0f); exp10f(0.0f); exp2f(0.0f); expf(0.0f); expm1f(0.0f); fX = fabsf(1.0f); fdimf(1.0f, 0.0f); fdividef(0.0f, 1.0f); fX = floorf(0.0f); fmaf(1.0f, 2.0f, 3.0f); fX = fmaxf(0.0f, 0.0f); fX = fminf(0.0f, 0.0f); fmodf(0.0f, 1.0f); frexpf(0.0f, &iX); hypotf(1.0f, 0.0f); ilogbf(1.0f); isfinite(0.0f); fX = isinf(0.0f); fX = isnan(0.0f); j0f(0.0f); j1f(0.0f); jnf(-1.0f, 1.0f); ldexpf(0.0f, 0); lgammaf(1.0f); llrintf(0.0f); llroundf(0.0f); log10f(1.0f); log1pf(-1.0f); log2f(1.0f); logbf(1.0f); logf(1.0f); lrintf(0.0f); lroundf(0.0f); modff(0.0f, &fX); fX = nanf("1"); fX = nearbyintf(0.0f); nextafterf(0.0f, 0.0f); norm3df(1.0f, 0.0f, 0.0f); norm4df(1.0f, 0.0f, 0.0f, 0.0f); normcdff(0.0f); normcdfinvf(1.0f); fX = 1.0f; normf(1, &fX); powf(1.0f, 0.0f); rcbrtf(1.0f); remainderf(2.0f, 1.0f); remquof(1.0f, 2.0f, &iX); rhypotf(0.0f, 1.0f); fY = rintf(1.0f); rnorm3df(0.0f, 0.0f, 1.0f); rnorm4df(0.0f, 0.0f, 0.0f, 1.0f); fX = 1.0f; rnormf(1, &fX); fY = roundf(0.0f); rsqrtf(1.0f); scalblnf(0.0f, 1); scalbnf(0.0f, 1); signbit(1.0f); sincosf(0.0f, &fX, &fY); sincospif(0.0f, &fX, &fY); sinf(0.0f); sinhf(0.0f); sinpif(0.0f); sqrtf(0.0f); tanf(0.0f); tanhf(0.0f); tgammaf(2.0f); fY = truncf(0.0f); y0f(1.0f); y1f(1.0f); ynf(1, 1.0f); }
npy_float npy_log1pf(npy_float x) { return log1pf(x); }