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

Function fxNumberToInteger

xs/sources/xsdtoa.c:6420–6454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6418}
6419
6420txInteger fxNumberToInteger(txNumber theValue)
6421{
6422#if defined(pebble)
6423 if (c_fpclassify(theValue) == C_FP_NORMAL) {
6424 #define MODULO 4294967296.0
6425 txNumber aNumber = c_fmod(c_trunc(theValue), MODULO);
6426 if (aNumber >= MODULO / 2)
6427 aNumber -= MODULO;
6428 else if (aNumber < -MODULO / 2)
6429 aNumber += MODULO;
6430 return (txInteger)aNumber;
6431 }
6432 return 0;
6433#else
6434 int lb = c_ilogb(theValue);
6435 if ((C_FP_ILOGB0 == lb) || (C_FP_ILOGBNAN == lb))
6436 return 0;
6437
6438 if (lb < 31)
6439 return (txInteger)theValue;
6440
6441 if (C_INT_MAX == lb)
6442 return 0;
6443
6444 theValue = c_trunc(theValue);
6445 #define MODULO 4294967296.0
6446 theValue = c_fmod(theValue, MODULO);
6447 if (theValue >= MODULO / 2)
6448 theValue -= MODULO;
6449 else if (theValue < -MODULO / 2)
6450 theValue += MODULO;
6451
6452 return (txInteger)theValue;
6453#endif
6454}
6455
6456txString fxNumberToString(void* the, txNumber theValue, txString theBuffer, txSize theSize, txByte theMode, txInteger thePrecision)
6457{

Callers 3

ifFunction · 0.85
xsRun.cFile · 0.85
fxToIntegerFunction · 0.85

Calls 1

c_fpclassifyFunction · 0.85

Tested by

no test coverage detected