From: Mark H Weaver <mhw@netris.org>
To: Hans Aberg <haberg-1@telia.com>
Cc: guile-devel@gnu.org
Subject: Re: RFC: Arbitrary-precision floats for Guile
Date: Tue, 01 Feb 2011 12:03:27 -0500 [thread overview]
Message-ID: <87sjw7vg9s.fsf@yeeloong.netris.org> (raw)
In-Reply-To: <D80249FF-14EC-4042-B710-FFEE9C756DFD@telia.com> (Hans Aberg's message of "Tue, 1 Feb 2011 15:28:38 +0100")
Hans Aberg <haberg-1@telia.com> writes:
>> There would be a fluid whose value would determine the minimum precision
>> to use for inexact operators. A value of #f (the default) would mean
>> that normal floats would be used unless one of the operands was a
>> bigfloat.
>
> Only checking takes a lot of time, so it is best to make a new
> type. Same for integral types. So if speed is an issue, Guile ought to
> have C99 integral types.
>
> The name 'floating' seems free for such a type.
I'm not sure I understand. These type checks would only be added as
additional cases to the generic arithmetic operators, which
unfortunately cannot avoid checking the types of their arguments for
each operation. Sadly this is already the case. Currently Guile
supports fixnums (small integers), arbitrary-precision integers,
arbitrary-precision rationals, IEEE 64-bit floats, and complex numbers
composed of IEEE 64-bit floats. All of these cases must be considered
on each operation. To make matters worse, all of these types except
small integers must be allocated on on the heap. Therefore every
floating point operation involves heap allocation, and additionally pays
the amortized cost of garbage collecting the number later on.
The only additional overhead added to existing floating point operations
would be to check the value of the fluid. Admittedly this is not
entirely trivial, but I think it will be lost in the noise compared with
the overheads already present.
>> One complication is that we'd have to implement the transcendental
>> functions. However, I already have code to do that, as part of a
>> bigfloat library I wrote a while back.
>
> There is already MPFR, which is a package of top of GMP (see the
> manual of the latter).
Excellent, thanks for the pointer! MPFR seems to contain all of the
functionality I need, so this will make my job much easier.
>> I'd also like to add another more general representation of complex
>> numbers whose real and imaginary parts are each of type SCM, like the
>> way fractions are represented.
>
> One might have a complexification class with one template
> argument. The current Guile 'complex' type is (in my installation) the
> complexification of 64-bit IEEE floats.
Please forgive me if I misunderstand, but it seems to me that you are
thinking in terms of static type checking, which is wholly different
from how Guile operates internally. Although I don't see a need for
complex numbers whose real and imaginary parts are of different types,
it would require additional implementation complexity to enforce this
constraint. I'm not sure it's worth the effort. My plan is to simply
call the generic arithmetic operators recursively to operate on the real
and imaginary parts.
Have I misunderstood you? I would very much like to understand.
Thanks,
Mark
next prev parent reply other threads:[~2011-02-01 17:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-01 13:57 RFC: Arbitrary-precision floats for Guile Mark H Weaver
2011-02-01 14:28 ` Hans Aberg
2011-02-01 16:42 ` dsmich
2011-02-01 17:03 ` Mark H Weaver [this message]
2011-02-01 19:20 ` Hans Aberg
2011-02-01 20:37 ` Andy Wingo
2011-02-02 14:30 ` Hans Aberg
-- strict thread matches above, loose matches on Subject: below --
2011-02-02 1:53 Nelson H. F. Beebe
2011-02-02 15:42 ` Pierpaolo Bernardi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sjw7vg9s.fsf@yeeloong.netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=haberg-1@telia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).