[gambit-list] Patch to improve elementary functions for complex and exact arguments
Marc Feeley
feeley at iro.umontreal.ca
Thu Oct 30 17:06:02 EDT 2008
Thanks Brad! The patch is not committed to the repository. Note that
your tests give slightly different results on my machine (as far as I
can see probably only the least significant bit is different).
Marc
On 30-Oct-08, at 3:53 PM, Bradley Lucier wrote:
> 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
>
> <_num.scm-diff><test-log.scm><old-results.gz><new-results.gz>
More information about the Gambit-list
mailing list