@@ -74,7 +74,7 @@ The extra 2 bytes are for the quotes around the string
74
74
*/
75
75
#define RESERVE_STRING (_len ) (2 + ((_len)*6))
76
76
77
- static const double g_pow10 [] = {1 ,
77
+ static const long double g_pow10 [] = {1 ,
78
78
10 ,
79
79
100 ,
80
80
1000 ,
@@ -784,29 +784,29 @@ void Buffer_AppendLongUnchecked(JSONObjectEncoder *enc, JSINT64 value) {
784
784
enc -> offset += (wstr - (enc -> offset ));
785
785
}
786
786
787
- int Buffer_AppendDoubleUnchecked (JSOBJ obj , JSONObjectEncoder * enc ,
788
- double value ) {
787
+ int Buffer_AppendLongDoubleUnchecked (JSOBJ obj , JSONObjectEncoder * enc ,
788
+ long double value ) {
789
789
/* if input is beyond the thresholds, revert to exponential */
790
- const double thres_max = (double )1e16 - 1 ;
791
- const double thres_min = (double )1e-15 ;
790
+ const long double thres_max = (long double )1e16 - 1 ;
791
+ const long double thres_min = (long double )1e-15 ;
792
792
char precision_str [20 ];
793
793
int count ;
794
- double diff = 0.0 ;
794
+ long double diff = 0.0 ;
795
795
char * str = enc -> offset ;
796
796
char * wstr = str ;
797
797
unsigned long long whole ;
798
- double tmp ;
798
+ long double tmp ;
799
799
unsigned long long frac ;
800
800
int neg ;
801
- double pow10 ;
801
+ long double pow10 ;
802
802
803
803
if (value == HUGE_VAL || value == - HUGE_VAL ) {
804
- SetError (obj , enc , "Invalid Inf value when encoding double" );
804
+ SetError (obj , enc , "Invalid Inf value when encoding long double" );
805
805
return FALSE;
806
806
}
807
807
808
808
if (!(value == value )) {
809
- SetError (obj , enc , "Invalid Nan value when encoding double" );
809
+ SetError (obj , enc , "Invalid Nan value when encoding long double" );
810
810
return FALSE;
811
811
}
812
812
@@ -825,12 +825,12 @@ int Buffer_AppendDoubleUnchecked(JSOBJ obj, JSONObjectEncoder *enc,
825
825
precision_str [0 ] = '%' ;
826
826
precision_str [1 ] = '.' ;
827
827
#if defined(_WIN32 ) && defined(_MSC_VER )
828
- sprintf_s (precision_str + 2 , sizeof (precision_str ) - 2 , "%ug " ,
828
+ sprintf_s (precision_str + 2 , sizeof (precision_str ) - 2 , "%uLg " ,
829
829
enc -> doublePrecision );
830
830
enc -> offset += sprintf_s (str , enc -> end - enc -> offset , precision_str ,
831
831
neg ? - value : value );
832
832
#else
833
- snprintf (precision_str + 2 , sizeof (precision_str ) - 2 , "%ug " ,
833
+ snprintf (precision_str + 2 , sizeof (precision_str ) - 2 , "%uLg " ,
834
834
enc -> doublePrecision );
835
835
enc -> offset += snprintf (str , enc -> end - enc -> offset , precision_str ,
836
836
neg ? - value : value );
@@ -915,6 +915,7 @@ int Buffer_AppendDoubleUnchecked(JSOBJ obj, JSONObjectEncoder *enc,
915
915
return TRUE;
916
916
}
917
917
918
+
918
919
/*
919
920
FIXME:
920
921
Handle integration functions returning NULL here */
@@ -942,7 +943,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name,
942
943
This reservation must hold
943
944
944
945
length of _name as encoded worst case +
945
- maxLength of double to string OR maxLength of JSLONG to string
946
+ maxLength of long double to string OR maxLength of JSLONG to string
946
947
*/
947
948
948
949
Buffer_Reserve (enc , 256 + RESERVE_STRING (cbName ));
@@ -1077,8 +1078,18 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name,
1077
1078
}
1078
1079
1079
1080
case JT_DOUBLE : {
1080
- if (!Buffer_AppendDoubleUnchecked (obj , enc ,
1081
- enc -> getDoubleValue (obj , & tc ))) {
1081
+ if (!Buffer_AppendLongDoubleUnchecked (obj , enc ,
1082
+ (long double ) enc -> getDoubleValue (obj , & tc ))) {
1083
+ enc -> endTypeContext (obj , & tc );
1084
+ enc -> level -- ;
1085
+ return ;
1086
+ }
1087
+ break ;
1088
+ }
1089
+
1090
+ case JT_LONGDOUBLE : {
1091
+ if (!Buffer_AppendLongDoubleUnchecked (obj , enc ,
1092
+ enc -> getLongDoubleValue (obj , & tc ))) {
1082
1093
enc -> endTypeContext (obj , & tc );
1083
1094
enc -> level -- ;
1084
1095
return ;
0 commit comments