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

Function fxNumberToString

xs/sources/xsdtoa.c:6456–6649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6454}
6455
6456txString fxNumberToString(void* the, txNumber theValue, txString theBuffer, txSize theSize, txByte theMode, txInteger thePrecision)
6457{
6458 ThInfo DTOA;
6459 char* base = C_NULL;
6460 int mode, precision, decpt, sign, count, exponent, pad;
6461 char* start;
6462 char* stop;
6463 char* result;
6464
6465 fxDTOASetup(the, &DTOA);
6466 switch (theMode) {
6467 case 'e':
6468 if (thePrecision > 0) {
6469 mode = 2;
6470 precision = thePrecision;
6471 }
6472 else {
6473 mode = 0;
6474 precision = 0;
6475 }
6476 break;
6477 case 'f':
6478 mode = 3;
6479 precision = thePrecision;
6480 break;
6481 case 'g':
6482 mode = 2;
6483 precision = thePrecision;
6484 break;
6485 default:
6486 mode = 0;
6487 precision = 0;
6488 break;
6489 }
6490 base = start = fx_dtoa(theValue, mode, precision, &decpt, &sign, &stop, &DTOA);
6491 count = mxPtrDiff(stop - start);
6492 result = theBuffer;
6493 theSize--; // C string
6494 if (sign && theValue) {
6495 *result++ = '-';
6496 theSize--;
6497 }
6498 if (decpt != 9999) {
6499 switch (theMode) {
6500 case 'e':
6501 exponent = 1;
6502 if (thePrecision > 0)
6503 pad = thePrecision;
6504 else
6505 pad = count;
6506 break;
6507 case 'f':
6508 exponent = 0;
6509 pad = thePrecision;
6510 break;
6511 case 'g':
6512 if ((decpt < -5) || (thePrecision < decpt)) {
6513 exponent = 1;

Callers 14

fxNewFunctionNameFunction · 0.85
fxKeyAtFunction · 0.85
fxNewFunctionNameFunction · 0.85
fxToStringFunction · 0.85
fxPropertyNameFunction · 0.85
fxObjectBindingFunction · 0.85
fxIsCanonicalIndexFunction · 0.85
fxEchoNumberFunction · 0.85
fxVerifyErrorStringFunction · 0.85

Calls 4

fxDTOASetupFunction · 0.85
fx_dtoaFunction · 0.85
freedtoaFunction · 0.85
fxDTOACleanupFunction · 0.85

Tested by

no test coverage detected