Skip to content

Commit

Permalink
add note about BigFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
tinybike committed Aug 26, 2014
1 parent e2643e8 commit 3e9b48f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Basic routines for decimal arithmetic in Julia. Supports addition, subtraction, negation, multiplication, division, and equality operations; exponentiation coming as soon as I find the time to write it. This is a pure Julia implementation, so if you are concerned about pure speed, calling `libmpdec` functions directly is likely to be faster. Tested in Julia v. 0.3.0-prerelease+4028.

Update: I have discovered recently that the built-in `BigFloat` already fills this niche in Julia. I suggest using this instead of `Decimal`, as it has a more complete feature set, and is probably faster, too :)

### Background

Why is this needed? Because floating point arithmetic does things like this:
Expand Down

2 comments on commit 3e9b48f

@jmkuhn
Copy link

@jmkuhn jmkuhn commented on 3e9b48f Apr 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the README you suggest using BigFloat instead of Decimal. BigFloat is not a good replacement for Decimal. Although it uses more bits to store the floats than Float64, it is still a binary float format that doesn't provide an exact representation for all floats.

One example:

julia> x = trunc(BigFloat("2.10") * 100) / 100
2.090000000000000000000000000000000000000000000000000000000000000000000000000015e+00 with 256 bits of precision

julia> @printf("%.2f\n", x) # lost a penny
2.09

A Decimal package is an important compliment to BigFloat.

@tinybike
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I guess I misunderstood the purpose of BigFloat. I'll have to come back and finish Decimal when I've got a bit of time, then!

Please sign in to comment.