unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Arne Babenhauserheide <arne_bab@web.de>
To: arne.babenhauserheide@kit.edu
Cc: arne_bab@web.de, guile-devel@gnu.org
Subject: Re: [PATCH] Allow giving floating point values to (sleep).
Date: Sun, 26 Jun 2016 23:37:15 +0200	[thread overview]
Message-ID: <871t3j3a44.fsf@web.de> (raw)
In-Reply-To: <8c8510a889e2d3b9f57f.1463767657@imkpcghg.imk-asf.kit.edu>

[-- Attachment #1: Type: text/plain, Size: 2032 bytes --]

ping?

arne.babenhauserheide@kit.edu writes:

> # HG changeset patch
> # User Arne Babenhauserheide <arne.babenhauserheide@kit.edu>
> # Date 1463764424 -7200
> #      Fri May 20 19:13:44 2016 +0200
> # Node ID 8c8510a889e2d3b9f57f5b3057f5ed0e001ab799
> # Parent  0d961f25dfa2a5e421e3bd9d816740a736647cbc
> initial inelegant implementation of (sleep) which takes floats
>
> diff -r 0d961f25dfa2 -r 8c8510a889e2 libguile/scmsigs.c
> --- a/libguile/scmsigs.c	Wed May 18 22:18:51 2016 +0200
> +++ b/libguile/scmsigs.c	Fri May 20 19:13:44 2016 +0200
> @@ -625,14 +625,25 @@
>  
>  SCM_DEFINE (scm_sleep, "sleep", 1, 0, 0,
>             (SCM i),
> -	    "Wait for the given number of seconds (an integer) or until a signal\n"
> -	    "arrives.  The return value is zero if the time elapses or the number\n"
> -	    "of seconds remaining otherwise.\n"
> +	    "Wait for the given number of seconds (an integer or float)\n"
> +	    "or until a signal arrives.  The return value is zero if the time\n"
> +	    "elapses or the number of seconds remaining otherwise.\n"
>  	    "\n"
>  	    "See also @code{usleep}.")
>  #define FUNC_NAME s_scm_sleep
>  {
> -  return scm_from_uint (scm_std_sleep (scm_to_uint (i)));
> +  SCM one, million, i_sleep, i_usleep, res_sleep, res_usleep;
> +  if (SCM_LIKELY (scm_is_integer (i)))
> +    return scm_from_uint (scm_std_sleep (scm_to_uint (i)));
> +  one = scm_from_int (1);
> +  million = scm_from_int (1000000);
> +  /* Time to wait in sleep */
> +  i_sleep = scm_inexact_to_exact (scm_floor_quotient (i, one));
> +  /* Time to wait in usleep */
> +  i_usleep = scm_inexact_to_exact (scm_floor_quotient (scm_product (million, scm_floor_remainder (i, one)), one));
> +  res_sleep = scm_from_uint (scm_std_sleep (scm_to_uint (i_sleep)));
> +  res_usleep = scm_from_ulong (scm_std_usleep (scm_to_ulong (i_usleep)));
> +  return scm_sum(res_sleep, res_usleep);
>  }
>  #undef FUNC_NAME
>  


-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

  reply	other threads:[~2016-06-26 21:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20 18:07 [PATCH] Allow giving floating point values to (sleep) arne.babenhauserheide
2016-06-26 21:37 ` Arne Babenhauserheide [this message]
2016-06-27  8:10   ` 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=871t3j3a44.fsf@web.de \
    --to=arne_bab@web.de \
    --cc=arne.babenhauserheide@kit.edu \
    --cc=guile-devel@gnu.org \
    /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).