Re: The 'Value' of Basic Maths (was: Basic Maths)

2001-01-28 Thread Pierre Sahores

Jacqueline Landman Gay a écrit :
> 
> > Original conundrum...
> >
> > >Type this in the message box...
> > >put 5.45 - 4 = 1.45  FALSE
> >
> 
> I am getting flak on the HyperCard mailing list for mentioning MetaCard,
> so I suppose I may as well round out my career by mentioning that
> HyperCard does this math just fine, no errors. So there must be a way
> around it; maybe it's a MetaCard thing.
> 
> --
> Jacqueline Landman Gay | [EMAIL PROTECTED]
> HyperActive Software   | 612-724-1596
> Custom hypermedia solutions| http://www.hyperactivesw.com
> 
> Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
> Info: http://www.xworlds.com/metacard/mailinglist.htm
> Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Don't worry Jacque... integrists are ever and ever stored in theyr integrism
close boxes :-)
We are lots to remember what you did for and with hc.

Kind Regards, Pierre Sahores

WEB & VPN applications and databases servers
Inspection académique de la Seine-Saint-Denis
Penser la part du rêve et produire l'avantage

Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.




Re: The 'Value' of Basic Maths (was: Basic Maths)

2001-01-28 Thread Jacqueline Landman Gay

> Original conundrum...
> 
> >Type this in the message box...
> >put 5.45 - 4 = 1.45  FALSE
> 

I am getting flak on the HyperCard mailing list for mentioning MetaCard,
so I suppose I may as well round out my career by mentioning that
HyperCard does this math just fine, no errors. So there must be a way
around it; maybe it's a MetaCard thing.

-- 
Jacqueline Landman Gay | [EMAIL PROTECTED]
HyperActive Software   | 612-724-1596
Custom hypermedia solutions| http://www.hyperactivesw.com



Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.




The 'Value' of Basic Maths (was: Basic Maths)

2001-01-28 Thread Hugh Senior

Original conundrum...

>Type this in the message box...
>put 5.45 - 4 = 1.45  FALSE

So we have a sever dose of the floating point accuracies, huh John?

>On the surface, it appears to me that this is an interesting example of how
>roundoff errors in computer calculations can cause programming headaches if
>your logic is testing for absolute equality.

Claude agrees:
>As a workaround you can use round(myNumber,nDigits) 
>
>put round((5.45-4),10)-round((1.45),10)=0 TRUE

John's observation below hints at a curious solution, however...

>The moral of the story is to never build logic into numerical programs
>that relies on recognizing precise equality of two floating point numbers.

put VALUE(5.45 - 4) = 1.45 TRUE

Presumably, 'value' applies a different set of rules.
 
At least I have a solution for my accounts validation check, but I do feel
a computer should manage basic subtraction. There was a discussion about
this a while ago, essentially explaining how computers behave this way.
No-one to the best of my recollection actually explained why they have to,
however.

The moral of this story is to remember your values.

/H

Hugh Senior

The Flexible Learning Company
Consultant Programming & Software Solutions
Fax/Voice: +44 (0)1483.27 87 27
Email: [EMAIL PROTECTED]
Web: www.flexibleLearning.com

Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.




Re: Basic Maths

2001-01-28 Thread Claude Lemmel

Hugh Senior wrote :

> put 5.45 - 3 = 2.45  TRUE
> but...
> put 5.45 - 4 = 1.45  FALSE

Same bug on my Pentium based computer.
Even
put 5.45 - 4.0 = 1.45  FALSE

Pentium's or mc's bug ?

As a workaround you can use round(myNumber,nDigits) 

put round((5.45-4),10)-round((1.45),10)=0 TRUE


Claude



Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.




Re: Basic Maths

2001-01-27 Thread John Kiltinen

Hugh Senior wrote:

>Type this in the message box...
>
>put 5.45 - 1 = 4.45  TRUE
>put 5.45 - 2 = 3.45  TRUE
>put 5.45 - 3 = 2.45  TRUE
>
>but...
>
>put 5.45 - 4 = 1.45  FALSE
>
>Huh? This is not helping my sanity, nor writing a finance checking routine
>that answers false instead of true!
>
>Any answers out there?

On the surface, it appears to me that this is an interesting example of how
roundoff errors in computer calculations can cause programming headaches if
your logic is testing for absolute equality.  As a further test, I did the
subtractions Hugh did, and then went on to substract the supposed
difference, which logically ought to produce 0.  The tests worked out this
way:

put (5.45 - 1) - 4.45 = 0  TRUE
put (5.45 - 2) - 3.45 = 0  TRUE
put (5.45 - 3) - 2.45 = 0  TRUE
put (5.45 - 4) - 1.45 = 0  FALSE

These results are consistent with Hugh's.

Now focussing on the last case, let us test this differece which ought to
be equal to zero but which the computer says is not zero to see how small
the computer agrees that it is in absolute value.  These were my results
with MetaCard:

put abs((5.45 - 4) - 1.45) < 0.0001  FALSE
put abs((5.45 - 4) - 1.45) < 0.001   TRUE

Thus, it appears that the roundoff error that occurs when substracting 4
from 5.45, and then further subtracting 1.45 from that is in the 16th
decimal place.

The moral of the story is to never build logic into numberical programs
that relies on recognizing precise equality of two floating point numbers.
You can count on precision, however, with integer arithmetic, provided you
do not get so large as to produce overflow errors.  For example, if we
multiply Hugh's example by 100 to get all the numbers being integers,
MetaCard says:

put 545 - 400 = 145  TRUE

Pardon me if this may be more detailed than some readers of this list may
care to see.  It's the math prof in me.

Since this is my first post, let me introduce myself.  I am a professor of
mathematics at Northern Michigan University.  I am interested in MetaCard
because it is allowing me to upgrade and make more broadly available some
permutation puzzles that I developed in HyperCard for use in teaching one
of my courses some years ago.  I ported them over to MetaCard over a year
ago, and did some improvements on them at the time.  Now I am doing a more
intensive upgrade.

I have found reading this list to be very helpful over the past year that I
have been getting it.  Now that I am getting more into working with
MetaCard, you may hear from me with questions from time to time.

Don't look for answers from here that have to do with the hard core
computer programming, however.  I am a reluctant programmer, doing it only
when I have a project that wouldn't get done otherwise.

John Kiltinen



 John Kiltinen ([EMAIL PROTECTED])Home  Office
 Professor, Dept. of Math. & CS   Tel.(906) 228-8035 or (906) 227-1600
 Northern Michigan University Fax (906) 228-4667 or (906) 2272010
 Marquette, MI 49855 USA




Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.




Basic Maths

2001-01-27 Thread Hugh Senior

Type this in the message box...

put 5.45 - 1 = 4.45  TRUE
put 5.45 - 2 = 3.45  TRUE
put 5.45 - 3 = 2.45  TRUE

but...

put 5.45 - 4 = 1.45  FALSE

Huh? This is not helping my sanity, nor writing a finance checking routine
that answers false instead of true!

Any answers out there?

/H

Hugh Senior

The Flexible Learning Company
Consultant Programming & Software Solutions
Fax/Voice: +44 (0)1483.27 87 27
Email: [EMAIL PROTECTED]
Web: www.flexibleLearning.com

Archives: http://www.mail-archive.com/metacard@lists.runrev.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.