guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Allow giving floating point values to (sleep).


From: Arne Babenhauserheide
Subject: Re: [PATCH] Allow giving floating point values to (sleep).
Date: Sun, 26 Jun 2016 23:37:15 +0200
User-agent: mu4e 0.9.16; emacs 24.5.1

ping?

address@hidden writes:

> # HG changeset patch
> # User Arne Babenhauserheide <address@hidden>
> # 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: signature.asc
Description: PGP signature


reply via email to

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