Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python can't divide??!?!

Thread Tools

Python can't divide??!?!

Josiah Carlson
Posts: n/a
Axle wrote:
> Yes, python can divide... use the / operator

He was referring to the inaccuracy of binary vs. decimal
representations. Most Computer Science students don't learn about it
until sophomore year of college in their computer architectures class.

3.0 / 5.0 -> .6 in decimal.

When we're dealing with floating point arithmetic in Python (or any
other language that uses IEEE 754 double-precision floating point
representations), 3.0 / 5.0 is internally represented as:
00111111111000110011001100110011001100110011001100 11001100110011

If we then convert that back into decimal, we get .59999999999999998.

Binary representation thanks to:

- Josiah
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 R. David Murray Python 0 01-17-2011 02:23 PM
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 Senthil Kumaran Python 0 01-17-2011 10:31 AM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Martin v. L÷wis Python 0 03-01-2008 10:51 PM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Paul Moore Python 0 03-01-2008 10:39 PM
Searching comp.lang.python/ (was: UTF-8) Python 0 03-10-2007 02:50 PM