On Mon, 10 Aug 2020 at 10:48, wei zhao <
zwleop...@gmail.com> wrote:
>
> emmmmm, i just hope mpir tries to add 0s at the end when conversion.
It doesn't add *anything* at the end. There is nothing after the end.
Once you reach the limit of the precision, there is no further data
after that point.
Finite precision means there's a finite number of bits. There's
nothing after those bits. Only finitely many bits are stored.
>
> i tried mpf_set_str(), it seems give me correct result.
It will give you the nearest approximation to the decimal value using
the the precision you set.
mpf is NOT a decimal system, it is a binary system. I think you are
confused about this. There is no exact conversion between fractional
decimal numbers to a given (decimal) precision and fractional binary
numbers to a given (binary) precision. The precision in mpf is a
BINARY precision, not a decimal one. You can lose information
converting between decimal and binary! That has nothing to do with
mpf. It is a feature of the mathematics itself.
The random digits you see are because you lost information converting
from decimal to binary and back again. mpf does not store the decimal
number. It stores a binary approximation. So when you convert back to
decimal, some information is gone and cannot be retrieved.
Think about it, how would YOU write 0.1 decimal in binary? It's not
possible in a finite number of bits.
Bill.
> To unsubscribe from this group and stop receiving emails from it, send an email to
mpir-devel+...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/mpir-devel/095760f7-9477-40e7-9e96-015df643e7c4o%40googlegroups.com.