If you know your flonum is within the range of fixnums you can use the very efficient ##flonum->fixnum which will basically compile to a cast (correct me Marc if i'm wrong).

On Wed, Oct 29, 2008 at 8:20 PM, Darren Baker <darren@wildfire.com.au> wrote:
Hi Taylor,

I do agree but it's only *mostly* absurd I would argue. :)

If I know I have a flonum within a known range, and I always want it as
a fixnum, then this does the job, and I imagine skips a bunch of checks
that would be irrelevant in this case (pls correct me if wrong though!)

If you use (##c-code ... ) inline then the C callout is gone...  and on
GCC / Intel the conversion will compile to a cvttsd2si instruction.

I am just putting a pragmatic / performance view here, it's definitely
not elegant.

Obviously if inexact->exact has higher performance, eg because it's an
optimizable intrinsic, then this method is categorically rubbish. :)  I
haven't checked yet though.

Cheers,
Darren



Taylor R Campbell wrote:
>    Date: Thu, 30 Oct 2008 08:37:32 +1000
>    From: Darren Baker <darren@wildfire.com.au>
>
>    This is no doubt Very Bad Practice but it's useful :)
>
>    (define flonum->fixnum
>        (c-lambda (double) int "___result = (int)___arg1;"))
>
> That's absurd!  Aside from the obvious absurdity of calling out to C
> for this, it leads to nasal demons if the range of the argument's
> integral part exceeds the range of C ints or Gambit fixnums.  There is
> a perfectly good standard procedure to obtain the nearest exact number
> to an inexact one, which one may have obtained by rounding another
> inexact number.  This procedure is called INEXACT->EXACT.
>
>
>

--
Darren Baker
CEO, CTO
Wildfire Studios Pty. Ltd.
Ph: +61 7 3844 1000
Fax: +61 7 3844 8970
www.wildfire.com.au

The information in this message is confidential and may be legally
privileged.  It is intended solely for the addressee.  Access to this
message by anyone else is unauthorised.  If you are not the intended
recipient,  any disclosure,  copying or distribution of the message,  or
any action taken by you in reliance on it,  is prohibited and may be
unlawful.  If you have received this message in error,  please delete it
and contact the sender immediately.  Thank you.

_______________________________________________
Gambit-list mailing list
Gambit-list@iro.umontreal.ca
https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list