I am interested in working on the project ideas Formalizing the interaction between Abilities (Typeclasses) and Defunctionalization and High-performance fixed-point operations for decimal numbers. Is one of them feasible without having worked on Roc so far?
High-performance fixed-point operations for decimal numbers definitely is!
that one can be done pretty much entirely in Zig - here is the current code: https://github.com/roc-lang/roc/blob/9cb3a3fb2b502885e95e0a3c61186cfaa3f6d0b1/src/builtins/dec.zig#L15
we're missing things like trig functions, sqrt, etc.
happy to answer any questions about it...would be amazing to have those! :heart_eyes:
On top of that, what already exists likely has room for profiling and optimizations.
Richard Feldman said:
happy to answer any questions about it...would be amazing to have those! :heart_eyes:
Where do I start? Do you already have any references for sqrt? I have found these libraries, dec and arithmetic.go, that seem to implement operations for decimal numbers.
dec: https://docs.rs/dec/latest/dec/index.html
arithmetic.go: https://github.com/jokruger/dec128/blob/main/arithmetic.go#L262
Hi @Alexander Ikonomou :)
Do you already have any references for sqrt?
Not that I know of.
Where do I start?
I think it would be good to get a working sqrt merged in before doing a high perf one.
So, specifically, this program should work:
app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" }
import cli.Stdout
import cli.Arg exposing [Arg]
main! : List Arg => Result {} _
main! = |_args|
four = 4dec
sqrt = Num.sqrt(four)
Stdout.line!(Num.to_str(sqrt))
NumSqrtUnchecked
should be added here. DEC_SQRT
should be added here.
And a sqrt function should be added here. Claude sonnet 4 can probably generate the sqrt function if you provide it the whole file.
It would help to clarify if this should be implemented in the new Zig compiler or the old Rust one. Richard's link above is to the new builtins in the zig compiler /src
directory.
Anton's links are to the old Rust compiler.
And they are using different versions of the zig builtins implementations.
We don't have the ability to run things in the new zig compiler yet... so we'd would probably be limited to unit tests for now, or maybe hooking up the fuzzer somehow.
That being said, it may not be that far away that we have a basic interpreter working.
Anton's links are to the old Rust compiler.
Right, sorry I totally forgot to consider that
Although maybe implementing it in the old compiler is a great way to test it for now?
Do we handle things differently in the new compiler builtins compared to the old?
We will be handling things differently. We don't really have much of an implementation in the new compiler that links the Roc and Zig together. But we do have the zig builtins translated to use the same zig version as the new compiler.
Ok, yeah, so just unit tests for the new compiler sounds fine
@Alexander Ikonomou so src/builtins/dec.zig is the only file you need to make changes in. Unit tests are in that same file.
Where do I start?
I think it would be good to get a working sqrt merged in before doing a high perf one.
So, specifically, this program should work:
In 7861, I added a working sqrt that just uses the sqrt from Zig. I am not sure if it is too simple.
Long term we want to avoid many of the casts to and from float, but this is fine for now.
Last updated: Jul 06 2025 at 12:14 UTC