Function cJSON_CreateNumber

Synopsis

#include <cJSON.h>

cJSON * cJSON_CreateNumber(double num)

Description

No description yet.

Mentioned in

Source

Lines 2420-2444 in cJSON.c. Line 199 in cJSON.h.

CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num)
{
    cJSON *item = cJSON_New_Item(&global_hooks);
    if(item)
    {
        item->type = cJSON_Number;
        item->valuedouble = num;

        /* use saturation in case of overflow */
        if (num >= INT_MAX)
        {
            item->valueint = INT_MAX;
        }
        else if (num <= (double)INT_MIN)
        {
            item->valueint = INT_MIN;
        }
        else
        {
            item->valueint = (int)num;
        }
    }

    return item;
}





Add Discussion as Guest

Log in