chadaustin / sajson

Lightweight, extremely high-performance JSON parser for C++11
MIT License
564 stars 41 forks source link

TYPE_INTEGER is a C double? #4

Closed tedx closed 7 years ago

tedx commented 10 years ago

get_number_value on a node of type TYPE_INTEGER returns a double is this the expected behaviour?

chadaustin commented 10 years ago

get_number_value has to return a double because double is the only type that can hold both 32-bit integers and 64-bit floats.

If you know you have an integer and you want the value as an integer, you can get call get_integer_value.

tedx commented 10 years ago

Wouldn't a long work for TYPE_INTEGER?

chadaustin commented 10 years ago

long would work too. On all platforms I've used in recent history, sizeof(long) == sizeof(int). Why do you ask?

chadaustin commented 10 years ago

Or are you asking why get_number_value() doesn't return a long? If so, the answer is, if get_number_value() was called on a TYPE_DOUBLE, how could a 'long' contain the fractional part of the number?