473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in floating-point addition: is anyone else seeing this?

On SuSE 10.2/Xeon there seems to be a rounding bug for
floating-point addition:

dickinsm@weyl:~ python
Python 2.5 (r25:51908, May 25 2007, 16:14:04)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>a = 1e16-2.
a
999999999999999 8.0
>>a+0.999 # gives expected result
999999999999999 8.0
>>a+0.9999 # doesn't round correctly.
100000000000000 00.0

The last result here should be 999999999999999 8.0,
not 100000000000000 00.0. Is anyone else seeing this
bug, or is it just a quirk of my system?

Mark
Jun 27 '08 #1
31 1611
Mark Dickinson schrieb:
On SuSE 10.2/Xeon there seems to be a rounding bug for
floating-point addition:

dickinsm@weyl:~ python
Python 2.5 (r25:51908, May 25 2007, 16:14:04)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>>a = 1e16-2.
a
999999999999999 8.0
>>>a+0.999 # gives expected result
999999999999999 8.0
>>>a+0.9999 # doesn't round correctly.
100000000000000 00.0

The last result here should be 999999999999999 8.0,
not 100000000000000 00.0. Is anyone else seeing this
bug, or is it just a quirk of my system?
It is working under OSX:

(TG1044)mac-dir:~/projects/artnology/Van_Abbe_RMS/Van-Abbe-RMS deets$ python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright" , "credits" or "license" for more information.
Welcome to rlcompleter2 0.96
for nice experiences hit <tabmultiple times
>>a = 1e16-2.
a
999999999999999 8.0
>>a+0.9999
999999999999999 8.0
>>>
But under linux, I get the same behavior:

Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
Welcome to rlcompleter2 0.96
for nice experiences hit <tabmultiple times
>>a = 1e16-2.
a+0.9999
100000000000000 00.0
>>>

So - seems to me it's a linux-thing. I don't know enough about
IEEE-floats to make any assumptions on the reasons for that.

Diez
Jun 27 '08 #2
On May 21, 11:38 am, Mark Dickinson <dicki...@gmail .comwrote:
On SuSE 10.2/Xeon there seems to be a rounding bug for
floating-point addition:

dickinsm@weyl:~ python
Python 2.5 (r25:51908, May 25 2007, 16:14:04)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.>>a = 1e16-2.
>a
999999999999999 8.0
>a+0.999 # gives expected result
999999999999999 8.0
>a+0.9999 # doesn't round correctly.

100000000000000 00.0

The last result here should be 999999999999999 8.0,
not 100000000000000 00.0. Is anyone else seeing this
bug, or is it just a quirk of my system?

Mark
I see it too
Jun 27 '08 #3
Mark Dickinson <di******@gmail .comwrote:
On SuSE 10.2/Xeon there seems to be a rounding bug for
floating-point addition:

dickinsm@weyl:~ python
Python 2.5 (r25:51908, May 25 2007, 16:14:04)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>>a = 1e16-2.
a
999999999999999 8.0
>>>a+0.999 # gives expected result
999999999999999 8.0
>>>a+0.9999 # doesn't round correctly.
100000000000000 00.0

The last result here should be 999999999999999 8.0,
not 100000000000000 00.0. Is anyone else seeing this
bug, or is it just a quirk of my system?
On my system, it works:

Python 2.5.2 (r252:60911, May 21 2008, 18:49:26)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>a = 1e16 - 2.; a
999999999999999 8.0
>>a + 0.9999
999999999999999 8.0

Marc
Jun 27 '08 #4
On May 21, 3:22*pm, Marc Christiansen <use...@solar-empire.dewrote:
On my system, it works:

*Python 2.5.2 (r252:60911, May 21 2008, 18:49:26)
*[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
*Type "help", "copyright" , "credits" or "license" for more information.
*>>a = 1e16 - 2.; a
*99999999999999 98.0
*>>a + 0.9999
*99999999999999 98.0

Marc
Thanks for all the replies! It's good to know that it's not just
me. :-)

After a bit (well, quite a lot) of Googling, it looks as though this
might be known problem with gcc on older Intel processors: those using
an x87-style FPU instead of SSE2 for floating-point. This gcc
'bug' looks relevant:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323

Now that I've got confirmation I'll open a Python bug report: it's
not clear how to fix this, or whether it's worth fixing, but it
seems like something that should be documented somewhere...

Thanks again, everyone!

Mark
Jun 27 '08 #5
On Wed, May 21, 2008 at 3:56 PM, Dave Parker
<da********@fla mingthunder.com wrote:
On May 21, 2:44 pm, "Jerry Hill" <malaclyp...@gm ail.comwrote:
>My understand is no, not if you're using IEEE floating point.

Yes, that would explain it. I assumed that Python automatically
switched from hardware floating point to multi-precision floating
point so that the user is guaranteed to always get correctly rounded
results for +, -, *, and /, like Flaming Thunder gives. Correct
rounding and accurate results are fairly crucial to mathematical and
scientific programming, in my opinion.
--
If you're going to use every post and question about Python as an
opportunity to pimp your own pet language you're going irritate even
more people than you have already.
Jun 27 '08 #6
On Wed, May 21, 2008 at 4:56 PM, Dave Parker
<da********@fla mingthunder.com wrote:
On May 21, 2:44 pm, "Jerry Hill" <malaclyp...@gm ail.comwrote:
>My understand is no, not if you're using IEEE floating point.

Yes, that would explain it. I assumed that Python automatically
switched from hardware floating point to multi-precision floating
point so that the user is guaranteed to always get correctly rounded
results for +, -, *, and /, like Flaming Thunder gives. Correct
rounding and accurate results are fairly crucial to mathematical and
scientific programming, in my opinion.
However, this is not an issue of language correctness, it's an issue
of specification and/or hardware. If you look at the given link, it
has to do with the x87 being peculiar and performing 80-bit
floating-point arithmetic even though that's larger than the double
spec. I assume this means FT largely performs floating-point
arithmetic in software rather than using the FP hardware (unless of
course you do something crazy like compiling to SW on some machines
and HW on others depending on whether you trust their functional
units).

The fact is, sometimes it's better to get it fast and be good enough,
where you can use whatever methods you want to deal with rounding
error accumulation. When accuracy is more important than speed of
number crunching (and don't argue to me that your software
implementation is faster than, or probably even as fast as, gates in
silicon) you use packages like Decimal.

Really, you're just trying to advertise your language again.
Jun 27 '08 #7
On May 21, 3:17*pm, "Chris Mellon" <arka...@gmail. comwrote:
If you're going to use every post and question about Python as an
opportunity to pimp your own pet language you're going irritate even
more people than you have already.
Actually, I've only posted on 2 threads that were questions about
Python -- this one, and the one about for-loops where the looping
variable wasn't needed. I apologize if that irritates you. But maybe
some Python users will be interested in Flaming Thunder if only to
check the accuracy of the results that they're getting from Python,
like I did on this thread. I think most people will agree that having
two independent programs confirm a result is a good thing.
Jun 27 '08 #8
On May 21, 3:19*pm, "Dan Upton" <up...@virginia .eduwrote:
The fact is, sometimes it's better to get it fast and be good enough,
where you can use whatever methods you want to deal with rounding
error accumulation.
I agree.

I also think that the precision/speed tradeoff should be under user
control -- not at the whim of the compiler writer. So, for example,
if a user says:

Set realdecimaldigi ts to 10.

then it's okay to use hardware double precision, but if they say:

Set realdecimaldigi ts to 100.

then it's not. The user should always be able to specify the
precision and the rounding mode, and the program should always provide
correct results to those specifications.
Jun 27 '08 #9
On Wed, May 21, 2008 at 4:29 PM, Dave Parker
<da********@fla mingthunder.com wrote:
On May 21, 3:17 pm, "Chris Mellon" <arka...@gmail. comwrote:
>If you're going to use every post and question about Python as an
opportunity to pimp your own pet language you're going irritate even
more people than you have already.

Actually, I've only posted on 2 threads that were questions about
Python -- this one, and the one about for-loops where the looping
variable wasn't needed. I apologize if that irritates you. But maybe
some Python users will be interested in Flaming Thunder if only to
check the accuracy of the results that they're getting from Python,
like I did on this thread. I think most people will agree that having
two independent programs confirm a result is a good thing.
--
Please don't be disingenuous. You took the opportunity to pimp your
language because you could say that you did this "right" and Python
did it "wrong". When told why you got different results (an answer you
probably already knew, if you know enough about IEEE to do the
auto-conversion you alluded to) you treated it as another opportunity
to (not very subtly) imply that Python was doing the wrong thing. I'm
quite certain that you did this intentionally and with full knowledge
of what you were doing, and it's insulting to imply otherwise.

You posted previously that you wrote a new language because you were
writing what you wanted every other language to be. This is very
similar to why Guido wrote Python and I wish you the best of luck. He
was fortunate enough that the language he wanted also happened to be
the language that lots of other people wanted. You don't seem to be so
fortunate, and anti-social behavior on newsgroups dedicated to other
languages is unlikely to change that. You're not the first and you
won't be the last.
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3390
by: Chris Gurk | last post by:
Hi Newsgroup, I am working on a website http://www.charter-yachtcharter.com/testsite/ (still in progress). There are two lists. The first is a simple paragraph (<p>-Tag), the second an unordered list. How can I use a Style-Sheet to format the bullets to be aligned like the text above. The problem is the floating catamaran-image which is floating left around the first paragraph on this site.
1
2638
by: James Walker | last post by:
Hi there, i'm having a problem when a list appears immediately after a floating div element... the bullet points or numbers appear behind the image in both IE and Firefox... i've tried wrapping the list item in a div and setting the margins and padding of the list but they seem to refer to the far left of the page so if i've got two floating divs next to each then a wider padding or margin is required ... here's my code: <HTML> <HEAD>
6
26060
by: Simon Wigzell | last post by:
How do a create a floating div that will always stay in the same place relative to the browser window as the user scrolls the main page? I guess an adaptation of one of these floating menus that always stay in view would work but I just need the few lines of code to keep it positioned a certain x and y pix location from the window top left corner... Thanks!
11
1290
by: Tuvas | last post by:
I would like to limit a floating variable to 4 signifigant digits, when running thorugh a str command. Ei, x=.13241414515 y=str(x)+" something here" But somehow limiting that to 4 sign. digits. I know that if you use the print statement, you can do something like %.4d, but how can I do this with converting the number to a string? Thanks!
2
12217
by: Isaac Varghese | last post by:
HI, Is it possible to create a floating/dockable form in C# winforms. Something similar to Properties/Solution Explorer window in Visual Studio.net or Search/Index window in MSDN. Any help or input is appreciated. Thanks in advance Isaac Varghese TCS
2
2402
by: Abhishek | last post by:
I am creating an application in C# wherein I require to add a toolbar. that is no problem and that is done as well. What I need now is that the toolbar that i insert should be a floating toolbar e.g. any toolbar in Office application is a floating toolbar . One can drag them anywhere and also fix it on the top. How do I get my toolbar to be a floating one One thing more, i want that my toolbars,menus, buttons all should have a Win Xp...
6
1515
by: Usenet | last post by:
I might be being silly here. On my links page I've got a whole load of floating boxes, which I'm really pleased with. But then I want the footer to be *below* them. On my current site (http://www.vowleyfarm.co.uk/CommunityLinks.htm) I've cheated by putting the footer in a floating box as well, but now I'm moving to using a CMS I would like not to hack my page template in this way.
2
2992
by: Qiang | last post by:
Those who have used Google notebook may notice that google notebook displays the notes in a small floating window of the browser. I have tried to create a similar floating window, but with no luck. Dojo has a sample floating window, but that floating window has to exist in a browser page, but looks like Google's floating window can exist independently. I also tried to debug the google notebook javascript code. It has two compressed...
4
2915
by: Ivor Somerset | last post by:
Dear CSS community, The code below shows my problem. I have a containing DIV box into which I place floating boxes. As the background-color shows, the size of the containing box is not extended by the inner floating boxes. Without the float, it works as expected. Why? What is it I am missing here about the CSS box model? Thanks in advance for your help.
4
2928
by: tbirnseth | last post by:
I'm having trouble between IE and FF. For once, IE behaves as I would expect, but FF doesn't. Basically I have a container with two floating DIVs in it. One floats left and the other right. I then have a table which should fill between the two floating DIVs if there is space. If there's not space, it should push down and display as a separately centered table. IE (7) behaves as I would expect, but FF seems to overlay the right side of the...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.