Open anton-trunov opened 2 months ago
We can't just port them to Tact stdlib and remove the .fc
files, because functions defined there are used in code generation, e.g. src/generator/writers/writeStdlib.ts
.
That's right. I meant some additional functions that can be used by Tact users.
@anton-trunov should I implement the sqrt
function the same way as it works in mathlib.fc
or take a different approach?
@Gusarich I haven't checked how sqrt
is implemented in mathlib.fc, what are the alternatives you see?
@anton-trunov we can take this one: https://github.com/TonoxDeFi/open-contracts/blob/ebbb877e5ee6a9e506605c455c44b2b5223956f1/contracts/math/math.func#L26
or even implement a different algorithm. probably makes sense to benchmark these on different ranges of integers to see what is more gas efficient
probably makes sense to benchmark these on different ranges of integers to see what is more gas efficient
agreed!
@anton-trunov turns out both of these implementation use the same Newton-Raphson method, but the one from tonox openlib does it in constant time (hardcoded 7 iterations for any input) and also has worse initial approximation, so the mathlib implementation wins on all ranges of numbers in terms of gas, especially after a few minor optimizations.
I looked through some other algorithms for square root finding and seems that Newton-Raphson will be the best for TVM in general, so I suggest to proceed with that (from mathlib).
This is going to be very easy after #768 is resolved.
It is partially addressed in these issues:
496
618