LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
Search this Thread
Old 09-08-2008, 04:14 PM   #1
JMJ_coder
Member
 
Registered: Apr 2006
Distribution: Fedora
Posts: 478

Rep: Reputation: 30
Floating-Point Arithmetic Not Associative or Distributive?


Hello,

I'm taking a course in Computer Architecture, and one of the topics is on binary representations of numbers in the computer. One of the points that they make is that floating-point arithmetic is not associative nor distributive, but I just don't understand how (especially the associative part). Could someone please explain this to me?
 
Old 09-08-2008, 05:20 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,474

Rep: Reputation: 155Reputation: 155
Actually floating point arithmetic is associative and distributive.

Floating point numbers have a fixed length which means that round off errors are common. You have to give some consideration to the order of your calculations and the magnitude of your intermediate results to minimize the effect of round off errors. If you do a sequence of calculations in several different orders you can get several different final results depending on how fast the round off errors propagate through the various intermediate results. All of this is a consequence of round off errors and does not mean that floating point arithmetic is non-associative or non-distributive.

-----------------------
Steve Stites
 
Old 09-08-2008, 05:46 PM   #3
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
Quote:
All of this is a consequence of round off errors and does not mean that floating point arithmetic is non-associative or non-distributive.
Actually, that is exactly what it means. Associative means that A*(B*C) = (A*B)*C, but given roundoff errors and number magnitudes etc this can be easily shown to not be true in all cases with computer floating point arithmetic. Hence, computer fp arithmetic is not associative.

Similarly, distributive property says that (A+B)*C = A*C + B*C. Again, it is simple to show that this is not true using computer fp arithmetic.

The fact is that the breakdown of these rules is due to a defect in the floating point arithmetic scheme, where word size turns out to be very important. But the existence of the defect leads to the consequence.
 
Old 09-08-2008, 06:00 PM   #4
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,474

Rep: Reputation: 155Reputation: 155
jiml8

Semantically what you say is correct but it is misleading. Suppose a student programmer solves a complex calculation using two different valid arithmetic sequences and gets two different answers. When he asks what is wrong are you going to tell him that floating point arithmetic does not follow the rules of algebra or are you going to explain the effects of roundoff errors and number magnitudes on intermediate results?

---------------------
Steve Stites
 
Old 09-08-2008, 06:11 PM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
I am going to tell him that because of the limitations of the hardware, the numerical approximations to the mathematical functions are not associative or distributive, and therefore he has to pay attention to the order of his operations.
 
Old 09-08-2008, 06:38 PM   #6
amani
Senior Member
 
Registered: Jul 2006
Location: Kolkata, India
Distribution: 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware,
Posts: 2,758

Rep: Reputation: Disabled
From the practical point of view, the main thing is to keep track of the progression of errors.

In computer sci, you use the rationals and not the reals usually.

Formally floating point arithmetic is actually being done over a "set that is larger than the set of rationals".

Q - field of rationals

Define a reflexive and symmetric relation T on Q via

$(x,y)\,\in\,T$ iff <your limitation on bounds based condition>

Now the set of "maximal mutually T-related elements" will actually be larger than Q

When two 'floating point numbers' are being added, then such "maximal mutually T-related elements" are being added.

Best

A. Mani
 
Old 09-09-2008, 06:24 PM   #7
JMJ_coder
Member
 
Registered: Apr 2006
Distribution: Fedora
Posts: 478

Original Poster
Rep: Reputation: 30
Thanks jiml8, that's kind of what I thought, but I was (and still am a little) confused over the exact reason. What confuses me even more is that if you take floating-point arithmetic in the real world (outside of the confines of a digital circuit), then normal mathematical concepts apply. aaarrrggghhh!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
floating point exception srkbapanapalli Linux - Newbie 1 03-26-2008 11:38 AM
floating-point in script mitsos Programming 6 08-31-2006 07:14 AM
Floating Point in kernel 2.4.28 lucs Slackware 1 10-19-2005 08:33 AM
Floating point exception hemk76 Linux - Software 1 05-06-2005 11:49 PM
managing floating point vince_2x Linux - General 2 09-21-2004 09:05 PM


All times are GMT -5. The time now is 04:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration