ericlagergren / decimal

A high-performance, arbitrary-precision, floating-point decimal library.
https://godoc.org/github.com/ericlagergren/decimal
BSD 3-Clause "New" or "Revised" License
531 stars 62 forks source link

SetString("4e絙谶涩)鶤Ŭ廓+踁YÏ豒=iC÷綳") returns 4 instead of an error #166

Closed tzachshabtay closed 3 years ago

tzachshabtay commented 3 years ago

repro here: https://play.golang.org/p/xLn3Ds6SFjf

ericlagergren commented 3 years ago

According to the GDA spec, an invalid string (like your example) results in NaN.

The result of attempting to convert a string which does not have the syntax of a numeric string is [0,qNaN].

While I agree that it would be better to return an error here for a syntactically invalid string, the goal of this library is to adhere to the GDA spec. Plus, changing this would be a backward-incompatible change.

If you want to determine why SetString returned NaN, you can check for the ConversionSyntax Condition which is set when the input is syntactically invalid.

ericlagergren commented 3 years ago

I should update the docs, however, as they're not exactly clear.

tzachshabtay commented 3 years ago

@ericlagergren I'm ok with it returning a NaN, when I posted the issue it didn't return NaN though, it returned 4. I see now in the playground that it's fixed, it does return NaN, was there a recent change that fixed this? I can still reproduce this with the version used by SQLBoiler, I want to tell them to upgrade, do we know which version was this fixed in? Thanks.

ericlagergren commented 3 years ago

I just fixed it last night. https://github.com/ericlagergren/decimal/commit/f12e1f0a991056e646bffdde424d81f365aca94a

tzachshabtay commented 2 years ago

@ericlagergren is there any official release for this? Last release is from 2019 afaict. Thanks.

tzachshabtay commented 2 years ago

@ericlagergren any plans for an official release? 🙏