[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] newbie question about numbers

From: Peter Bex
Subject: Re: [Chicken-users] newbie question about numbers
Date: Sun, 7 Feb 2010 23:24:30 +0100
User-agent: Mutt/

On Sun, Feb 07, 2010 at 03:50:09PM -0300, Hugo Arregui wrote:
> Hi,
> I'm new in scheme, and, of course, in chicken too.

Hi and welcome!

> I've a few newbie doubts about numbers, I hope you can help me.
> First, reading the scheme report I notice about a set of complex
> numbers procedures:
> make-rectangular
> make-polar
> real-part
> etc
> I found some of them implemented in chicken (without extensions), but
> miss others. Specifically: make procedures. It's sound very strange to
> me.

Like R5RS says:

"Implementations of Scheme are not required to implement the whole
  tower of subtypes given in section 6.2.1, but they must implement
  a coherent subset consistent with both the purposes of the
  implementation and the spirit of the Scheme language."

In the FAQ there is a rationale for why Chicken does not support the
full numeric tower by default.  In short, you can load the "numbers"
egg to get the full numeric tower.

> In other hand, I've doubts about number representations and exactness:
> Can I represent a big integer as an exact number?
> For example, when I try "#e2000000000", I get this error:
> (inexact->exact) inexact number cannot be represented as an exact
> number: 2000000000.0

After loading numbers, this error goes away and Chicken will behave as
you expect.

> In the Scheme revision I read: "For this purpose, numerical constants
> may be written with an exponent marker that indicates the desired
> precision of the inexact representation. The letters s, f, d, and l
> specify the use of short, single, double, and long precision,
> respectively.". Are these representations available in chicken?

Chicken distinguishes between fixnums and flonums.  fixnums are numbers
representable by your computer's architecture, with one bit taken off
for tagging.  So on 32 bit that would be -2^31 through +(2^32 - 1).

flonums are numbers representable by your machine's "double".  This is
a number in IEEE floating point format which is quite complex :)

The upshot of all this is that flonums can represent bigger numbers
(even integral ones) than fixnums, so Chicken will fall back to using
flonums when numbers you give it don't fit in a fixnum.

I hope this explains it a bit!

"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth

reply via email to

[Prev in Thread] Current Thread [Next in Thread]