Error: bigNumberify out of range when subtracting UInt #1347
-
I am implementing an API such as this: const V = API('SPP', {
increaseCapacity: Fun([UInt], UInt),
decreaseCapacity: Fun([UInt], UInt)
});
// ...
const [done, capacity, output] =
parallelReduce([false, 0, 0])
.invariant(balance() == 0)
.while(!done)
.api(V.increaseCapacity,
((amount, k) => {
const newCapacity = capacity + amount;
k(newCapacity);
return [false, newCapacity, output]
}))
.api(V.decreaseCapacity,
((amount, k) => {
const newCapacity = amount > capacity ? 0 : (capacity - amount);
k(newCapacity);
return [false, newCapacity, output]
}))
.timeout(false); The complier doesn't give any errors, but when I call
Should |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
What you are experiencing is that arithmetic operations are treated as pure and We consider this to be too confusing and this will be changed in the next release. However, you can adapt today by changing to an |
Beta Was this translation helpful? Give feedback.
What you are experiencing is that arithmetic operations are treated as pure and
?:
is not lazy on pure operations. The documentation explains this --- https://docs.reach.sh/rsh/compute/#conditional-expressionWe consider this to be too confusing and this will be changed in the next release. However, you can adapt today by changing to an
if (.....) { .... } else { .... }