Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!csi!sam
From: sam@csi.jpl.nasa.gov (Sam Sirlin)
Subject: Re: A J bug?
Message-ID: <1992Jan23.014437.10419@csi.jpl.nasa.gov>
Originator: sam@kalessin
Sender: usenet@csi.jpl.nasa.gov (Network Noise Transfer Service)
Nntp-Posting-Host: kalessin
Organization: Jet Propulsion Laboratory, Pasadena, CA
References:  <WEG.92Jan22181330@mace.cc.purdue.edu>
Distribution: comp
Date: Thu, 23 Jan 1992 01:44:37 GMT


In article <WEG.92Jan22181330@mace.cc.purdue.edu>, weg@mace.cc.purdue.edu (Eythan Weg) writes:
|> I have written this version of Stirling's approximation to ! :
|>    stirling=.(( %:(o. 2))&*) & ((] ^ (0.5&+)) * (^&-))
|> and tested it on vax release 3.4  with dialogue:
|>    !30
|> 2.65253e32
|>    stirling 30
|> 3.99085e25
|> On J/PC version 4 I obatin this:
|>       stirling 30
|> 2.64517e32
|> Where exacltly is the bug?

I get the pc answer on my Sun sparc. One possible place to look is in
the representation of numbers. The vax uses fewer bits in the exponent
and more in the mantissa than the IEEE standard (Sun, pc). The largest
machine representable floating point number is then (from netlib
distribution of the gamma function)

C IEEE (IBM/XT,
C   SUN, etc.)   (D.P.)   1.79D+308    
C VAX D-Format   (D.P.)   1.70D+38     
C VAX G-Format   (D.P.)   8.98D+307

Perhaps you're using D and getting overflow? This is not then a bug in
J, but just one of the usual hardware issues. G-Format requires
software emulation and is thus more expensive, but is available if you
need it. Have you tried smaller numbers?

This is reinforced by the following on my Sun:

   !170
7.25742e306
   stirling 170
_.j_.
   
170 is the biggest number that ! works on, but stirling craps out
after 142, indicating that in its computations its using numbers
bigger than the answer.

-- 
Sam Sirlin
Jet Propulsion Laboratory         sam@kalessin.jpl.nasa.gov

