MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages


struct json_objectjson_object_new_double (double d)
struct json_objectjson_object_new_double_s (double d, const char *ds)
double json_object_get_double (struct json_object *obj)

Detailed Description

Function Documentation

struct json_object * json_object_new_double ( double  d)

Create a new empty json_object of type json_type_double

dthe double
a json_object of type json_type_double

Definition at line 622 of file json_object.c.

struct json_object * json_object_new_double_s ( double  d,
const char *  ds 

Create a new json_object of type json_type_double, using the exact serialized representation of the value.

This allows for numbers that would otherwise get displayed inefficiently (e.g. 12.3 => "12.300000000000001") to be serialized with the more convenient form.

Note: this is used by json_tokener_parse_ex() to allow for an exact re-serialization of a parsed object.

An equivalent sequence of calls is:

1 jso = json_object_new_double(d);
2 json_object_set_serializer(d, json_object_userdata_to_json_string,
3  strdup(ds), json_object_free_userdata)
dthe numeric value of the double.
dsthe string representation of the double. This will be copied.

Definition at line 632 of file json_object.c.

double json_object_get_double ( struct json_object obj)

Get the double floating point value of a json_object

The type is coerced to a double if the passed object is not a double. integer objects will return their double conversion. Strings will be parsed as a double. If no conversion exists then 0.0 is returned and errno is set to EINVAL. null is equivalent to 0 (no error values set)

If the value is too big to fit in a double, then the value is set to the closest infinity with errno set to ERANGE. If strings cannot be converted to their double value, then EINVAL is set & NaN is returned.

Arrays of length 0 are interpreted as 0 (with no error flags set). Arrays of length 1 are effectively cast to the equivalent object and converted using the above rules. All other arrays set the error to EINVAL & return NaN.

NOTE: Set errno to 0 directly before a call to this function to determine whether or not conversion was successful (it does not clear the value for you).

objthe json_object instance
a double floating point number

Definition at line 656 of file json_object.c.