unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: Neil Jerram <neiljerram@googlemail.com>
Cc: guile-user@gnu.org
Subject: Re: How to stay in fixnum range?
Date: Wed, 21 Jan 2009 10:54:11 +0100	[thread overview]
Message-ID: <1eb53f5d0901210154ra50ada8gc5e3e0b040b29743@mail.gmail.com> (raw)
In-Reply-To: <49dd78620901210100w74bf25c2m1842ccd705411c08@mail.gmail.com>

>> The problem may appear when I add some number to the
>> return value of get-internal-real-time -- what if, during addition,
>> the scheme fixnum limit is exceeded and the variable becomes
>> a bignum?
>
> It becomes a bignum.  Why is that a problem?
>
> (Serious question, because the best solution may depend on why this
> actually matters...)

I expect that, after reaching the maximum count (the range of int), the timer
twists back to zero, instead of growing boundlessly.

In that case, the following code may fail:

(define (for-ticks-pass-time-left ticks operation)
  (let ((total-ticks (+ ticks (get-internal-real-time)))
        (elapsed-ticks 0)
        (current-ticks 0)
        (processed-ticks 0))
    (while #t
      (set! current-ticks (get-internal-real-time))
      (set! elapsed-ticks (+ elapsed-ticks (- current-ticks processed-ticks)))
      (set! processed-ticks current-ticks)
      (if (>= elapsed-ticks total-ticks)
        (break))
      (operation (- total-ticks elapsed-ticks)))
    (- elapsed-ticks total-ticks)))

When the internal counter twists back to zero between the
(get-internal-real-time) in the let assignment and in the
while loop, the total-ticks becomes very large, and the
current-ticks is small, so it may take very very long time
for the loop to execute

If all the operations were performed in the modulo
arithmetics (as they are in low level languages), the
problem would solve automatically.

Obviously I could use the modulo division in all the assignments,
but that would cause additional unnecessary overhead.

Probably the best solution would be to implement the
function in C.

Best regards
M




  reply	other threads:[~2009-01-21  9:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-19 21:02 How to stay in fixnum range? Panicz Maciej Godek
2009-01-21  9:00 ` Neil Jerram
2009-01-21  9:54   ` Panicz Maciej Godek [this message]
2009-01-21 16:28     ` Ludovic Courtès
2009-01-21 17:52     ` Neil Jerram
2009-01-21 15:00 ` Andy Wingo

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=1eb53f5d0901210154ra50ada8gc5e3e0b040b29743@mail.gmail.com \
    --to=godek.maciek@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=neiljerram@googlemail.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).