MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / AR_TOINTEGER

Function AR_TOINTEGER

src/arithmetic/numeric_funcs/numeric_funcs.c:115–142  ·  view source on GitHub ↗

tries to convert input to integer

Source from the content-addressed store, hash-verified

113
114// tries to convert input to integer
115SIValue AR_TOINTEGER(SIValue *argv, int argc, void *private_data) {
116 SIValue arg = argv[0];
117 char *sEnd = NULL;
118
119 switch(SI_TYPE(arg)) {
120 case T_INT64:
121 return arg;
122 case T_DOUBLE:
123 // Remove floating point.
124 return SI_LongVal(floor(arg.doubleval));
125 case T_BOOL:
126 if(SIValue_IsTrue(arg)) {
127 return SI_LongVal(1);
128 }
129 return SI_LongVal(0);
130 case T_STRING:
131 if(strlen(arg.stringval) == 0) return SI_NullVal();
132 errno = 0;
133 double parsedval = strtod(arg.stringval, &sEnd);
134 /* The input was not a complete number or represented a number that
135 * cannot be represented as a double. */
136 if(sEnd[0] != '\0' || errno == ERANGE) return SI_NullVal();
137 // Remove floating point.
138 return SI_LongVal(floor(parsedval));
139 default:
140 return SI_NullVal();
141 }
142}
143
144// tries to convert input to float
145SIValue AR_TOFLOAT(SIValue *argv, int argc, void *private_data) {

Callers

nothing calls this directly

Calls 3

SI_LongValFunction · 0.85
SIValue_IsTrueFunction · 0.85
SI_NullValFunction · 0.85

Tested by

no test coverage detected