Fixed cjson to not need -lm any more, by adding an ipow() routine

to use instead of pow().
This commit is contained in:
jef 2012-10-25 22:14:02 -07:00
parent 4095757536
commit ea71aaeaee
4 changed files with 28 additions and 11 deletions

View File

@ -36,7 +36,7 @@ libiperf_a_SOURCES = \
# Specify the sources and various flags for the iperf binary
iperf3_SOURCES = main.c
iperf3_CFLAGS = -g -Wall
iperf3_LDADD = libiperf.a -lm
iperf3_LDADD = libiperf.a
iperf3_LDFLAGS =
# Specify the sources and various flags for the profiled iperf binary. This
@ -45,7 +45,7 @@ iperf3_profile_SOURCES = main.c \
$(libiperf_a_SOURCES)
iperf3_profile_CFLAGS = -pg -Wall
iperf3_profile_LDADD = libiperf.a -lm
iperf3_profile_LDADD = libiperf.a
iperf3_profile_LDFLAGS =
# Specify the sources and various flags for the test cases

View File

@ -268,7 +268,7 @@ libiperf_a_SOURCES = \
# Specify the sources and various flags for the iperf binary
iperf3_SOURCES = main.c
iperf3_CFLAGS = -g -Wall
iperf3_LDADD = libiperf.a -lm
iperf3_LDADD = libiperf.a
iperf3_LDFLAGS =
# Specify the sources and various flags for the profiled iperf binary. This
@ -277,7 +277,7 @@ iperf3_profile_SOURCES = main.c \
$(libiperf_a_SOURCES)
iperf3_profile_CFLAGS = -pg -Wall
iperf3_profile_LDADD = libiperf.a -lm
iperf3_profile_LDADD = libiperf.a
iperf3_profile_LDFLAGS =
# Specify the sources and various flags for the test cases

View File

@ -112,16 +112,33 @@ void cJSON_Delete( cJSON *c )
}
static double ipow( double n, int exp )
{
double r;
if ( exp < 0 )
return 1.0 / ipow( n, -exp );
r = 1;
while ( exp > 0 ) {
if ( exp & 1 )
r *= n;
exp >>= 1;
n *= n;
}
return r;
}
/* Parse the input text to generate a number, and populate the result into item. */
static const char *parse_number( cJSON *item, const char *num )
{
double n = 0, sign = 1, scale = 0;
int subscale = 0, signsubscale = 1;
double n = 0;
int sign = 1, scale = 0, subscale = 0, signsubscale = 1;
/* Could use sscanf for this? */
if ( *num == '-' ) {
/* Has sign. */
sign=-1;
sign = -1;
num++;
}
if ( *num == '0' )
@ -156,7 +173,7 @@ static const char *parse_number( cJSON *item, const char *num )
}
/* Put it together: number = +/- number.fraction * 10^+/- exponent */
n = sign * n * pow( 10.0, ( scale + subscale * signsubscale ) );
n = sign * n * ipow( 10.0, scale + subscale * signsubscale );
item->valuefloat = n;
item->valueint = n;
@ -173,7 +190,7 @@ static char *print_number( cJSON *item )
if ( fabs( ( (double) item->valueint ) - d ) <= DBL_EPSILON && d <= INT_MAX && d >= INT_MIN ) {
str = (char*) cJSON_malloc( 21 ); /* 2^64+1 can be represented in 21 chars. */
if ( str )
sprintf( str, "%d", item->valueint );
sprintf( str, "%lld", item->valueint );
} else {
str = (char*) cJSON_malloc( 64 ); /* This is a nice tradeoff. */
if ( str ) {

View File

@ -76,7 +76,7 @@ extern int cJSON_GetArraySize( cJSON *array );
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
extern cJSON *cJSON_GetArrayItem( cJSON *array, int item );
/* Get item "string" from object. Case insensitive. */
extern cJSON *cJSON_GetObjectItem( cJSON *object,const char *string );
extern cJSON *cJSON_GetObjectItem( cJSON *object, const char *string );
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
extern const char *cJSON_GetErrorPtr( void );
@ -93,7 +93,7 @@ extern cJSON *cJSON_CreateArray( void );
extern cJSON *cJSON_CreateObject( void );
/* These utilities create an Array of count items. */
extern cJSON *cJSON_CreateIntArray( long long *numbers,int count );
extern cJSON *cJSON_CreateIntArray( long long *numbers, int count );
extern cJSON *cJSON_CreateFloatArray( double *numbers, int count );
extern cJSON *cJSON_CreateStringArray( const char **strings, int count );