[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: infinities reformulated
On Thu, 2 Jun 2005, Aubrey Jaffer wrote:
> | From: Thomas Bushnell BSG <tb@xxxxxxxxxx>
> | There is no function "precision-of", so there is no need for an
> | answer. Arbitrarily big precision arithmetic (generally) works pretty
> | well; you carry around symbolic representations and operate on them.
>To first order:
> (define (precision-of x) (string-length (number->string x)))
>R5RS requires all numbers to have external representations; and it
>specifies the allowed formats.
I think the relevant section here is where it says that (paraphrase)
when exact numbers are operated on in such a way as to produce inexact
results, the results should have at least as much precision as the most
precise hardware floating-point representation available.
I read this as forbidding (or at least recommending against) immediate
floating-point representations that fit in 32 bits and truncate the
mantissa for a typetag. So, when
A) you take (sqrt 2) and
B) 2 is an exact number, and
C) your implementation cannot represent the result exactly,
the standard requires (or at least recommends) that your implementation
return a result with at least the "greatest hardware precision available",
which in most cases will be, I believe, what the C compiler refers to as
a "long" or "double" precision float.
But this is, of course, subject to some interpretation by different
implementors; Nothing in R5RS says that the hardware representation
must be used; only that at whatever is used must provide at least
as much precision. A squared, cubed, or n'th-powered representation
may be available to represent square roots, cube roots, or nth roots
exactly, for example. A logarithmic representation where the number
stored is an integer power of 1+epsilon may be used. Etc.
For heavy math work, I want to be able to specify the precision used,
in one of several ways; For example, by saying
(sqrt 2 :precision 128)
or (without keywords)
(sqrt 2 128)
or something. I think someone else has suggested that there ought
to be a different sqrt function for each desired precision, but I
don't like that method as much.