2626#include "stdlib/constants/float32/max_base10_exponent.h"
2727#include "stdlib/constants/float32/min_base10_exponent_subnormal.h"
2828
29- // 10^308 :
30- static const double HUGE_VALUE = 1.0e308 ;
29+ // 10^38 :
30+ static const float HUGE_VALUE = 1.0e38 ;
3131
32- // 10^-323
33- static const double TINY_VALUE = 1.0e-323 ;
32+ // 10^-45
33+ static const float TINY_VALUE = 1.0e-45 ;
3434
3535/**
3636* Rounds a numeric value to the nearest power of `10` on a linear scale.
@@ -39,18 +39,18 @@ static const double TINY_VALUE = 1.0e-323;
3939* @return rounded value
4040*
4141* @example
42- * double out = stdlib_base_round10 ( 3.141592653589793 );
42+ * float out = stdlib_base_round10f ( 3.141592653589793 );
4343* // returns 1.0
4444*/
45- double stdlib_base_round10 ( const double x ) {
46- double sign ;
47- double half ;
48- double p1 ;
49- double p2 ;
50- double y1 ;
51- double y2 ;
52- double xc ;
53- double p ;
45+ float stdlib_base_round10f ( const float x ) {
46+ float sign ;
47+ float half ;
48+ float p1 ;
49+ float p2 ;
50+ float y1 ;
51+ float y2 ;
52+ float xc ;
53+ float p ;
5454
5555 if ( stdlib_base_is_nan ( x ) || stdlib_base_is_infinite ( x ) || x == 0.0 ) {
5656 return x ;
@@ -64,25 +64,25 @@ double stdlib_base_round10( const double x ) {
6464 }
6565
6666 // Solve the equation `10^p = x` for `p`:
67- p = stdlib_base_log10 ( xc );
67+ p = stdlib_base_logf ( xc , 10.0 );
6868
6969 // Find the previous and next integer powers:
70- p1 = stdlib_base_floor ( p );
71- p2 = stdlib_base_ceil ( p );
70+ p1 = stdlib_base_floorf ( p );
71+ p2 = stdlib_base_ceilf ( p );
7272
7373 // Handle tiny:
74- if ( p1 == STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT_SUBNORMAL ) {
74+ if ( p1 == STDLIB_CONSTANT_FLOAT32_MIN_BASE10_EXPONENT_SUBNORMAL ) {
7575 return sign * TINY_VALUE ;
7676 }
7777
7878 // Handle huge:
79- if ( p1 == STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) {
79+ if ( p1 == STDLIB_CONSTANT_FLOAT32_MAX_BASE10_EXPONENT ) {
8080 return sign * HUGE_VALUE ;
8181 }
8282
8383 // Compute previous and next powers of 10:
84- y1 = stdlib_base_pow ( 10.0 , p1 );
85- y2 = stdlib_base_pow ( 10.0 , p2 );
84+ y1 = stdlib_base_pow ( 10.0 , ( float ) p1 );
85+ y2 = stdlib_base_pow ( 10.0 , ( float ) p2 );
8686
8787 // Find the closest power of 10:
8888 half = ( y2 - y1 ) / 2.0 ;
0 commit comments