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

Function fx_Math_sumPrecise

xs/sources/xsMath.c:615–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

613}
614
615void fx_Math_sumPrecise(txMachine* the)
616{
617 txSlot *iterable, *iterator, *next, *value;
618 xsum_small_accumulator accumulator;
619 txInteger count = 0;
620 txBoolean flag = 1;
621 if (mxArgc < 1)
622 mxTypeError("no items");
623 iterable = mxArgv(0);
624 fxToInstance(the, iterable);
625 mxTemporary(iterator);
626 mxTemporary(next);
627 fxGetIterator(the, iterable, iterator, next, 0);
628 xsum_small_init(&accumulator);
629 mxTemporary(value);
630 while (fxIteratorNext(the, iterator, next, value)) {
631 mxTry(the) {
632 if (value->kind == XS_INTEGER_KIND) {
633 flag = 0;
634 xsum_small_add1(&accumulator, value->value.integer);
635 }
636 else if (value->kind == XS_NUMBER_KIND) {
637 if (value->value.number != -0.0) {
638 flag = 0;
639 xsum_small_add1(&accumulator, value->value.number);
640 }
641 }
642 else
643 mxTypeError("items[%d]: not a number", count);
644 count++;
645 }
646 mxCatch(the) {
647 fxIteratorReturn(the, iterator, 1);
648 fxJump(the);
649 }
650 }
651 if (flag)
652 mxResult->value.number = -0.0;
653 else
654 mxResult->value.number = xsum_small_round(&accumulator);
655 mxResult->kind = XS_NUMBER_KIND;
656}
657
658void fx_Math_sign(txMachine* the)
659{

Callers

nothing calls this directly

Calls 8

fxToInstanceFunction · 0.85
fxGetIteratorFunction · 0.85
xsum_small_initFunction · 0.85
fxIteratorNextFunction · 0.85
xsum_small_add1Function · 0.85
fxIteratorReturnFunction · 0.85
fxJumpFunction · 0.85
xsum_small_roundFunction · 0.85

Tested by

no test coverage detected