-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support additional number bases #3
Comments
Great idea. I'll try to add this soon. |
I can add this if it's okay. |
Sure, you can if you want to. You mostly just need to modify the |
Yep already saw it |
As far as the idea about hex()/bin()/... functions goes, that's going to be a bit complicated. Those functions would need to produce strings, not numbers, and they could only be used as arguments within a print() function (because that is the only place where strings are allowed). ...So i suggest that we first just implement the parsing of numeric literals ( 0xFF, 0b010101, 0o746 ), and ignore the string formatting for now. |
Instead of using functions like hex()/bin()/oct()/..., another way to do the string formatting of alternate bases is by using printf-style formatting codes, like this: print("hex=%x dec=%d oct=%o bin=%b", 100, 100, 100, 100) I like Go's choice of formatting codes: https://golang.org/pkg/fmt/#hdr-Printing I am already planning to add printf codes to print(). In fact, my Go implementation of this library already has that feature, but dynamic string formatting is not a built-in feature in Rust, so I will need to implement it myself. |
The Rust formatting is really nice, but it is compile-time only. fasteval needs runtime formatting. Maybe we can find a way to re-use the Rust formatting infrastructure at runtime. |
Can't you just use the format macro? |
All macros are evaluated at compile-time. We need a solution that can perform string formatting at run-time. |
Ohh, yes you are right. |
I don't have much time at the moment. So the PR will take around a week. |
No problem. Take your time -- I appreciate your help. |
It would be very helpful if you can specify numbers in other bases, e.g. hexadecimal (0xFF) or binary (0b1001), and convert them via functions like in Python. (hex(255) -> 0xFF, bin(2) -> 10)
The text was updated successfully, but these errors were encountered: