You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-16)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\).
463
+
* Note that rescaling \\(x\\) can result in unexpected behavior. For instance, the result of \\(\\operatorname{roundnf}(0.2+0.1,-7)\\) is \\(0.30000001192092896\\) and not \\(0.3\\). While possibly unexpected, this is not a bug. The behavior stems from the fact that most decimal fractions cannot be exactly represented as floating-point numbers. And further, rescaling can lead to slightly different fractional values, which, in turn, affects the result of \\(\mathrm{roundf}\\).
// The maximum absolute single-precision float is ~3.4e38. Accordingly, any possible finite `x` rounded to the nearest >=10^39 is 0.0.
534
540
if ( n > MAX_EXP ) {
535
-
return f32( f32( 0.0 ) * x ); // preserve the sign (same behavior as roundf)
541
+
return f32( ZERO * x ); // preserve the sign (same behavior as roundf)
536
542
}
537
543
// If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding...
538
544
if ( n < MIN_EXP ) {
539
-
s = powf( f32( 10.0 ), -( n + MAX_EXP ) );
545
+
s = powf( TEN, -( n + MAX_EXP ) );
540
546
y = f32( f32( x * HUGE ) * s ); // order of operation matters!
541
547
if ( isInfinitef( y ) ) {
542
548
return x;
543
549
}
544
550
return f32( f32( roundf( y ) / HUGE ) / s );
545
551
}
546
-
s = powf( f32( 10.0 ), -n );
552
+
s = powf( TEN, -n );
547
553
y = f32( x * s );
548
554
if ( isInfinitef( y ) ) <spanclass="branch-0 cbranch-no" title="branch not covered" >{</span>
549
555
<spanclass="cstat-no" title="statement not covered" > return x;</span>
0 commit comments