# Assignment V equality (was: Bliss was Re: DEC program listing

Fred Cisin cisin at xenosoft.com
Wed Aug 17 17:27:13 CDT 2005

```On Wed, 17 Aug 2005, Tom Jennings wrote:
> > Many of them are actually otherwise intelligent, but they have not learned
> > how to think procedurally, and have been trained to think that '=' means
> > that two expressions are interchangable with each other.
> It's just these sorts of circumstances that justify physical
> violence.

The college administration (first against the wall when the revolution
comes?) get seriously upset about physical violence.
Classes started today.  They "are going to get back to me" in the next few
days to tell me which classes I'm te3aching!

Besides, it's not the fault of the students, it's just the concepts that
they learned in  "solving for the value of a variable", etc. in algebra in
the school system.

> But as Alan Turing pointed out, floating point arithmetic is NOT
> arithmetic. It's a valuable simulation (approximation) of
> arithmetic. Your example illustrates that perfectly. The need to
> normalize is the 2x4-upside-the-head hint that all is not well.
> The horrors involved are worse than Perl and BASIC combined.

Students who have never used a low level language, (INCLUDING CS GRADUATES
in many cases!),  have a VERY difficult time accepting the concept that
floating point is an approximation, and therefore a lot of "ordinary"
arithmetic principles don't apply.
I try to get them to never use an equality test with floating point.

I teach a beginning "Computer Math" class (when we can get a quorum).
In addition to the "increment by a unit smaller than the resolution",
another exaggeratedly simplistic example that I use to try to get them to
understand the inherent differences from "math" that floating point
approximations will introduce is:
"in decimal, using your calculator, divide 1 by 3.
write down the result, and turn off the calculator for 24 hours.
Then take the number that you wrote down (0.3333333) and multiply it by 3.
EXPLAIN what is wrong with the calculator to not give 1.0."

> float X;	     /* as IEEE 32 bit single precision */
> int n;
long n;
>
>  	X = 2147483648.0;
>  	n= 0;
>  	while (X == (X+1)) {
>  		printf "fa la la...\n";
>  		++n;
++X;
>  	}
>  	print ("%f combobulates %ld fa la la's.\n", X, n);
>
> Great! We love it!

or, as Dwight said,  "unless i is infinity"

--
Grumpy Ol' Fred     		cisin at xenosoft.com

```