cashscript
cashscript copied to clipboard
Emulate OP_MULDIV
In this BCR post OP_MULDIV is mentioned as a possible solution for overflowing intermediate values when multiplying and dividing after each other.
For example:
2^63 * 2^50 / 2^63
In the example above, the intermediate result of 2^63 * 2^50 would overflow, while the full result of 2^63 * 2^50 / 2^63 would not.
While OP_MULDIV doesn't exist now, some people are emulating this using division and modulo operations (e.g. the old AnyHedge).
We could abstract away this emulation into something like muldiv(2^63, 2^50, 2^63). That would make this emulation that contract devs do less error prone and much easier to read because it is handled by the compiler, not the developer.