Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ？
ulrich.eckhardt at dominolaser.com
Mon Oct 8 16:44:01 CEST 2012
Am 08.10.2012 16:07, schrieb iMath:
> To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ？
Algorithms are generally language-agnostic, so what is your question
> BTW ，Windows’s calculator get the accurate value ，anyone who knows how to implement it ?
You should use a library that handles arbitrary-precision floating point
numbers, Python's built-in floating point type corresponds to C's double
type and that is typically a IEEE float, which means a limited
precision. Just search the web for one. If you really want to do it
yourself, you could leverage the fact that Python's integral type has a
dynamic size, so that it can represent numbers with more than the
typical 32 or 64 bits width.
BTW: If this is not a homework question, you should ask much more
specifically. My anwers are intentionally vague in order to not spoil
you the learning effect.
More information about the Python-list