changeset 88:2f46f6491c04

Fix float AVP values handling
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 15 Jul 2008 13:56:30 +0900
parents d09e0dbe90e6
children e15ba31853ef
files include/waaad/dictionary-api.h waaad/dictionary.c waaad/main.c waaad/message.c waaad/tests/testmesg.c
diffstat 5 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/include/waaad/dictionary-api.h	Tue Jul 15 12:06:27 2008 +0900
+++ b/include/waaad/dictionary-api.h	Tue Jul 15 13:56:30 2008 +0900
@@ -438,8 +438,8 @@
 	int64_t     i64;	/* integer 64 */
 	uint32_t    u32;	/* unsigned 32 */
 	uint64_t    u64;	/* unsigned 64 */
-	double      f32;	/* float 32 */
-	long double f64;	/* float 64 */
+	float       f32;	/* float 32 */
+	double 	    f64;	/* float 64 */
 } avp_value_t;
 
 /* Type to hold data of named constants for AVP values */
--- a/waaad/dictionary.c	Tue Jul 15 12:06:27 2008 +0900
+++ b/waaad/dictionary.c	Tue Jul 15 13:56:30 2008 +0900
@@ -1251,11 +1251,11 @@
 			break;
 
 		case AVP_TYPE_FLOAT32:
-			log_debug("%g", (double)type_enum->enum_value.f32);
+			log_debug("%f", type_enum->enum_value.f32);
 			break;
 
 		case AVP_TYPE_FLOAT64:
-			log_debug("%Lg", type_enum->enum_value.f64);
+			log_debug("%g", type_enum->enum_value.f64);
 			break;
 		
 		default:
--- a/waaad/main.c	Tue Jul 15 12:06:27 2008 +0900
+++ b/waaad/main.c	Tue Jul 15 13:56:30 2008 +0900
@@ -238,7 +238,7 @@
 	}
 	
 	/* Start listening on Diameter port */
-	
+
 	/* Wait for ... something */
 	printf("Press 'enter' to terminate...\n");
 	getchar();
--- a/waaad/message.c	Tue Jul 15 12:06:27 2008 +0900
+++ b/waaad/message.c	Tue Jul 15 13:56:30 2008 +0900
@@ -480,11 +480,11 @@
 			break;
 
 		case AVP_TYPE_FLOAT32:
-			DUMP_VALUE("%g",(double)value->f32);
+			DUMP_VALUE("%f",value->f32);
 			break;
 
 		case AVP_TYPE_FLOAT64:
-			DUMP_VALUE("%Lg",value->f64);
+			DUMP_VALUE("%g",value->f64);
 			break;
 		
 		default:
@@ -520,7 +520,7 @@
 			break;
 
 		case AVP_TYPE_FLOAT32:
-			DUMP_CONST("%g",(double)value->enum_value.f32);
+			DUMP_CONST("%f",value->enum_value.f32);
 			break;
 
 		case AVP_TYPE_FLOAT64:
@@ -1013,11 +1013,11 @@
 			break;
 	
 		case AVP_TYPE_FLOAT32:
-			avp->avp_storage.f32 = (double)ntohl(*(uint32_t *)avp->avp_source);
+			avp->avp_storage.f32 = (float)ntohl(*(uint32_t *)avp->avp_source);
 			break;
 	
 		case AVP_TYPE_FLOAT64:
-			avp->avp_storage.f64 = (long double)ntohll(*(uint64_t *)avp->avp_source);
+			avp->avp_storage.f64 = (double)ntohll(*(uint64_t *)avp->avp_source);
 			break;
 	
 	}
--- a/waaad/tests/testmesg.c	Tue Jul 15 12:06:27 2008 +0900
+++ b/waaad/tests/testmesg.c	Tue Jul 15 13:56:30 2008 +0900
@@ -613,7 +613,12 @@
 			CHECK( 0x00, buf[25] ); /* length: 12 = 0x00000c */
 			CHECK( 0x00, buf[26] );
 			CHECK( 0x0C, buf[27] );
-			/* The remaining will be tested by successful parsing... */
+			CHECK( 0x40, buf[28] ); /* Value: 3.1415:  sign = '+' => most significant bit = 0 */
+			CHECK( 0x49, buf[29] ); /* 2 <= 3.1415 < 4 => exponent = 2 => biaised (on 8 bits) = (decimal) 129 = (binary) 100 0000 0 */
+			CHECK( 0x0e, buf[30] ); /* significand = (decimal) 0.57075 = (binary) 0.100 1001 0000 1110 0101 0110 */
+			CHECK( 0x56, buf[31] ); /* total => 0100 0000 0100 1001 0000 1110 0101 0110 = (hexa) 40 49 0e 56*/
+			
+			/* The other AVPs will be tested by successful parsing... */
 		}
 		
 		/* Now free the message, we keep only the buffer. */
"Welcome to our mercurial repository"