[gambit-list] Patch to improve elementary functions for complex and exact arguments

Bradley Lucier lucier at math.purdue.edu
Thu Oct 30 15:53:52 EDT 2008


Marc:

Here is a diff containing the following changes to _num.scm:

new macros: macro-exp-1/2, macro-exp--1/2, macro-log-2

new function: ##flonum.full-precision, which checks that (abs x) is  
finite and above the largest subnormal number.

In ##log:

Define exact-log, which gives a finite answer for extremely large and  
extremely small exact arguments, and better relative accuracy for  
exact rationals near 1.  It is slower than the old behavior of log on  
exact rationals near 1, so if you just want a quick and dirty  
approximation, use (log (exact->inexact x)).

Define complex-log-magnitude, which computes (log (magnitude x))  
carefully in one step instead of in two steps.

in ##atan2:

Return exact 0 if x and y are exact, x is positive, and y is 0.   
Carefully scale arguments before handling off to ##flonum.atan so more  
answers are finite.  Remove some checks, put them in calling functions.

in atan:

add checks before calling ##atan and ##atan2.

in ##sqrt:

Define complex-sqrt-magnitude, which carefully calculates (sqrt  
(magnitude x)) in one step instead of two.  For complex arguments,  
return an exact result where possible, e.g., (##sqrt +2i) => 1+i.



I've included a test program below, and the results of that test  
program in old-results and new-results.  Many previous +nan.0 and +inf. 
0 results are now finite; finite results that differ in more than the  
last bit or so have more accuracy.

Brad

-------------- next part --------------
A non-text attachment was scrubbed...
Name: _num.scm-diff
Type: application/octet-stream
Size: 12312 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20081030/0a54d9af/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-log.scm
Type: application/octet-stream
Size: 1518 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20081030/0a54d9af/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: old-results.gz
Type: application/x-gzip
Size: 15393 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20081030/0a54d9af/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: new-results.gz
Type: application/x-gzip
Size: 15608 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20081030/0a54d9af/attachment-0001.bin>


More information about the Gambit-list mailing list