[gentoo-user] Re: 69.99 != 69.99

2015-08-23 Thread Grant Edwards
On 2015-08-22, Alan McKinnon alan.mckin...@gmail.com wrote:

[regarding floating point comparison.]

 A good way to demonstrate just how problematic floats can be is to point
 out that floats are banned in the linux kernel for exactly this reason.
 Integers only.

Really?  The reason that I was given when I wanted to use FP in a
kernel module is that handing context switching for FP hardware is
much simpler/faster if you assume no FP operations in the kernel. 
Nobody ever mentioned the comparison problem or other typical FP
computation stumbles -- the decision was supposedly based on the
complications of handing FP hardware context switches.

-- 
Grant






[gentoo-user] Re: 69.99 != 69.99

2015-08-22 Thread walt
On Sat, 22 Aug 2015 16:57:41 +0200
hw h...@gartencenter-vaehning.de wrote:

 It is a recipe for disaster when you tell 
 your computer to print something but it prints something else instead.

The Android Stagefright exploit is a real-life example of exactly such a
disaster.

The arithmetic comparison in Stagefright was written in C, not perl,
and compared integers instead of floats, but the underlying fault is
the same in each case:  programming languages today assume that human
programmers think like machines.

Until that fundamental flaw is eliminated from all programming
languages, the problem will not go away.  That won't happen in my
lifetime, or yours.

And that is why I'm pouring another glass of wine and going to bed :)





Re: [gentoo-user] Re: 69.99 != 69.99

2015-08-22 Thread Fernando Rodriguez
On Saturday, August 22, 2015 7:40:31 PM walt wrote:
 On Sat, 22 Aug 2015 16:57:41 +0200
 hw h...@gartencenter-vaehning.de wrote:
 
  It is a recipe for disaster when you tell 
  your computer to print something but it prints something else instead.
 
 The Android Stagefright exploit is a real-life example of exactly such a
 disaster.

That's an integer overflow which is a different thing.
That's the same type of bug that brought down the Cluster spacecraft[1].
 
 The arithmetic comparison in Stagefright was written in C, not perl,
 and compared integers instead of floats, but the underlying fault is
 the same in each case:  programming languages today assume that human
 programmers think like machines.
 
 Until that fundamental flaw is eliminated from all programming
 languages, the problem will not go away.  That won't happen in my
 lifetime, or yours.

Neither integer overflows nor floating point's limited precission are flaws in 
programming languages. The flaws come when the languages are used improperly.

A better way to think about floating point is that it's handled more like we 
handle numbers in our head. For example, if I ask you how far you live from 
here? you'll probably say something like 3 miles, not 3.003221 miles. 
Because at that scale the inaccuracy is acceptable. Likewise floating points 
can handle very large and very small numbers by doing the same. They trade 
between accuracy and range and they do it automagically. Consider that between 
1.1 and 1.2 there's infinity possible values so it would take 
inifinite memory to store it.


1. https://en.wikipedia.org/wiki/Cluster_%28spacecraft%29
-- 
Fernando Rodriguez