Floating-Point Arithmetic Not Associative or Distributive?

GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

Click Here to receive this Complete Guide absolutely free.

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?

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.

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.

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?

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.

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!

LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.