MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxToNumber

Function fxToNumber

xs/sources/xsAPI.c:202–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202txNumber fxToNumber(txMachine* the, txSlot* theSlot)
203{
204again:
205 switch (theSlot->kind) {
206 case XS_UNDEFINED_KIND:
207 theSlot->kind = XS_NUMBER_KIND;
208 theSlot->value.number = C_NAN;
209 break;
210 case XS_NULL_KIND:
211 theSlot->kind = XS_NUMBER_KIND;
212 theSlot->value.number = 0;
213 break;
214 case XS_BOOLEAN_KIND:
215 theSlot->kind = XS_NUMBER_KIND;
216 if (theSlot->value.boolean == 0)
217 theSlot->value.number = 0;
218 else
219 theSlot->value.number = 1;
220 break;
221 case XS_INTEGER_KIND:
222 theSlot->kind = XS_NUMBER_KIND;
223 theSlot->value.number = theSlot->value.integer;
224 mxFloatingPointOp("integer to number");
225 break;
226 case XS_NUMBER_KIND:
227 break;
228 case XS_STRING_KIND:
229 case XS_STRING_X_KIND:
230 theSlot->kind = XS_NUMBER_KIND;
231 theSlot->value.number = fxStringToNumber(the, theSlot->value.string, 1);
232 mxMeterOne();
233 break;
234 case XS_SYMBOL_KIND:
235 mxTypeError("cannot coerce symbol to number");
236 break;
237 case XS_REFERENCE_KIND:
238 fxToPrimitive(the, theSlot, XS_NUMBER_HINT);
239 goto again;
240 default:
241 mxTypeError("cannot coerce to number");
242 break;
243 }
244 return theSlot->value.number;
245}
246
247void fxString(txMachine* the, txSlot* theSlot, txString theValue)
248{

Callers 15

fx_parseURLFunction · 0.85
fx_deepEqualSlotsFunction · 0.85
fxFindNumberFunction · 0.85
fx_setIntervalFunction · 0.85
fx_setTimeoutFunction · 0.85
fxCheckSetRecordFunction · 0.85
fxSumEntryFunction · 0.85
fx_Math_absFunction · 0.85
fx_Math_acosFunction · 0.85
fx_Math_acoshFunction · 0.85
fx_Math_asinFunction · 0.85
fx_Math_asinhFunction · 0.85

Calls 2

fxStringToNumberFunction · 0.85
fxToPrimitiveFunction · 0.85

Tested by

no test coverage detected