Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!howland.reston.ans.net!ix.netcom.com!netcomsv!uu3news.netcom.com!netcomsv!uucp3.netcom.com!slcgate!servio!servio!aland
From: aland@servio.slc.com (Alan Darlington)
Subject: Re: floating point errors with Digitalk ST-V
Message-ID: <1995Aug30.173656.1035@slc.com>
Sender: news@slc.com (USENET News)
Nntp-Posting-Host: servio
Organization: GemStone Systems, Inc., Beaverton OR, USA
References: <41v3i2$ai5@scotsman.ed.ac.uk>
Date: Wed, 30 Aug 1995 17:36:56 GMT
Lines: 48

olly@festival.ed.ac.uk (O Morgan) writes:
> I'm using Digitalk version 2.0 Smalltalk V under Windows 3.11 on a 486
> machine.
> 
> I'm having problems with the following  floating point exceptions:
> 
> 0.0 raisedTo: 2.   Gives me a 'Divide by zero' exeption,
> 
> A exp.    where A < -52000 gives me a Float underflow exception.
> 
> Is there a way to tell ST-V to shut up and just get on with it?  At the
> moment I'm having to write tests in my calculations, eg:
> (A =0) ifTrue: [val:=0] ifFalse:[val:= A raisedTo: 2].
> (A < -50) ifTrue:[val:=0] ifFalse: [val := A exp.].
> 
> Is there a switch somewhere to tell ST not to worry about these things
> and use common sense values?
> 
> thanks for any help,
> 
> Olly Morgan

The bad news is that the #raisedTo: bug is a really old one - I fixed
it in Digitalk's V/286 version of Smalltalk.

The good news is that you can fix them yourself!  For example,

  raisedTo: aNumber

    aNumber = 0 ifTrue:
      [^ 1].
    ...

It is usually much more productive to put the fix in the actual
method rather than put a work-around in many places in your code.
If you feel queasy about changing system code, you could write a
wrapper method (#myRaisedTo: or ??) that does the above and calls
#raisedTo: for non-zero numbers.

The #exp problem is a little more complicated, as you would
probably have to use an error handler around some parts of the
#exp code (a wrapper method might be easiest here).

Sorry, but I don't know of any magic switches.

  Hope this helps,
  Alan Darlington
    (standard disclaimer)
