-
Notifications
You must be signed in to change notification settings - Fork 391
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 UntypedBigdecType, BigdecType, Float32Type and Float64Type. #306
Conversation
So happy about native |
Only UntypedBigDec is used right now (which are only made by constant expressions or constant literals) which then gets converted to float32 or float64 upon usage, but it should be easy to also support bigdec in the future if we want. |
@@ -67,11 +68,13 @@ func RunFileTest(rootDir string, path string, nativeLibs bool, logger loggerFunc | |||
stdin := new(bytes.Buffer) | |||
stdout := new(bytes.Buffer) | |||
stderr := new(bytes.Buffer) | |||
filesPath := "./files" | |||
filesPath := "./files2" | |||
mode := ImportModeStdlibsPreferred | |||
if nativeLibs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was weird. looks like before there was a bug where the native functions were only being run in files2 (when it should be so for files1 instead), and somehow the tests were still passing anyways? well, either way, the intent was this.
UPDATE2:
Currently, BigdecType is almost arbitrary precision, except for hex_p notation (whatever it's called).
I don't understand how you can support numbers like 0x1p-53 without loss of precision, without some tricky system to manage precision across operations. Instead, it's supported to a precision of around 1024bits. Multiplication and division also have a precision of about 1024 digits. To be completely spec compatible, we might need to use big.Float or some other arbitrary precision library just to hold hex_p numbers, but I think it's better to keep it simple as is and just document the difference.
After this PR, it will become possible to upload the flowrate library with some simple modifications: (a) remove sync mutexes (for now, sync is not supported), and (b) remove time.Sleep() synchronous API.
UPDATE: if we don't need to worry about fusing *+, and if we panic upon NaN, and we don't use sin/cos etc, is there any nondeterminism at all? For now this PR just implements native operations. Meanwhile this article has a lot of references to cross check: https://gafferongames.com/post/floating_point_determinism/
Some insights:
For reference: https://stackoverflow.com/questions/2186788/is-there-an-open-source-c-c-implementation-of-ieee-754-operations, softfloat looks pretty good.
For now, since there are no other clear options for Go, we will use math/big.Float: