-
Notifications
You must be signed in to change notification settings - Fork 78
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
add bigdecimal #132
base: master
Are you sure you want to change the base?
add bigdecimal #132
Conversation
Attempt of #126 ( @pynixwang ) |
directly replace |
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.
See inline comments.
fea0303
to
4f81c1a
Compare
@will have you looked at this yet? |
@greenbigfrog thanks. I'm curious though why you said it requires #131? |
It requires a few patches that haven't been released yet (and back when I opened this PR, I had no idea rly how crystal's compiling worked). It only requires following PRs:
|
src/pg_ext/big_decimal.cr
Outdated
struct Numeric | ||
# Returns a BigDecimal representation of the numeric. This retains all precision. | ||
def to_big_d | ||
return BigDecimal.new("0") if nan? || ndigits == 0 |
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.
Just noticed that this should be BigDecimal.new(0)
to avoid unnecessary allocation...
The new patch has a travis failure @greenbigfrog
|
scientific notation is not support ? |
As said, you need the patches I linked in #132 (comment) |
a4be24c
to
5a01c3e
Compare
5a01c3e
to
d8082a2
Compare
d8082a2
to
e12b255
Compare
e12b255
to
764797e
Compare
Realized today that this doesn't allow to do math in the query itself (eg |
764797e
to
eac915b
Compare
# Returns a BigDecimal representation of the numeric. This retains all precision. | ||
def to_big_d | ||
return BigDecimal.new(0) if nan? || ndigits == 0 | ||
BigDecimal.new(to_s) |
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.
There is pg/pg_ext/big_rational
so this method can become:
def to_big_d : BigDecimal
to_big_r.to_big_d
end
In fact, maybe both files could be merged into a single pg/pg_ext/big
file?
Most likely not the optimal solution, but it'll do the job. Require #131 to work.
(This will most likely only work on master crystal)
This change is