From: Bradley Hintze on 12 Aug 2010 16:43 Hi all. Is there a way I can keep my floating point number as I typed it? For example, I want 34.52 to be 34.52 and NOT 34.5200000002. -- Bradley J. Hintze Graduate Student Duke University School of Medicine 801-712-8799
From: Grant Edwards on 12 Aug 2010 17:20 On 2010-08-12, Bradley Hintze <bradley.h(a)aggiemail.usu.edu> wrote: > Is there a way I can keep my floating point number as I typed it? No. > For example, I want 34.52 to be 34.52 and NOT 34.5200000002. You can't represent 34.52 using base-2 IEEE floating point (the HW floating point format used by pretty much all modern computers). 34.5200000002 is as close as you can get. When you enter a base-10 floating-point number, the computer will use the closest base-2 IEEE floating point number. Here are the nitty-gritty details: http://docs.sun.com/source/806-3568/ncg_goldberg.html Can you explain what your actual problem is? -- Grant Edwards grant.b.edwards Yow! I'm imagining a surfer at van filled with soy sauce! gmail.com
From: Grant Edwards on 12 Aug 2010 17:24 On 2010-08-12, Grant Edwards <invalid(a)invalid.invalid> wrote: > On 2010-08-12, Bradley Hintze <bradley.h(a)aggiemail.usu.edu> wrote: > >> Is there a way I can keep my floating point number as I typed it? > > No. > >> For example, I want 34.52 to be 34.52 and NOT 34.5200000002. > > You can't represent 34.52 using base-2 IEEE floating point (the HW > floating point format used by pretty much all modern computers). > 34.5200000002 is as close as you can get. > > When you enter a base-10 floating-point number, the computer will use > the closest base-2 IEEE floating point number. > > Here are the nitty-gritty details: > > http://docs.sun.com/source/806-3568/ncg_goldberg.html Here is a gentler intro: http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate -- Grant Edwards grant.b.edwards Yow! If I felt any more at SOPHISTICATED I would DIE gmail.com of EMBARRASSMENT!
From: Grant Edwards on 12 Aug 2010 17:25 On 2010-08-12, Grant Edwards <invalid(a)invalid.invalid> wrote: >> Here are the nitty-gritty details: >> >> http://docs.sun.com/source/806-3568/ncg_goldberg.html > > Here is a gentler intro: > > http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate And another good page: http://docs.python.org/tutorial/floatingpoint.html -- Grant Edwards grant.b.edwards Yow! I feel like I'm at in a Toilet Bowl with a gmail.com thumbtack in my forehead!!
From: Philip Semanchuk on 12 Aug 2010 17:25 On Aug 12, 2010, at 4:43 PM, Bradley Hintze wrote: > Hi all. > > Is there a way I can keep my floating point number as I typed it? For > example, I want 34.52 to be 34.52 and NOT 34.5200000002. Hi Bradley, Use the Decimal type instead. It's not as convenient as float, but it will give you a consistent representation of your numbers. The behavior of floating point numbers surprises a lot of people and has been discussed at length a number of times here (and elsewhere). If you're in the mood for EXTREMELY thorough coverage of the subject, you can read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html There's a gentler discussion of it here: http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding HTH Philip
|
Next
|
Last
Pages: 1 2 3 Prev: Decompressing a file retrieved by URL seems too complex Next: re.sub and variables |