unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Allow giving floating point values to (sleep).
@ 2016-05-20 18:07 arne.babenhauserheide
  2016-06-26 21:37 ` Arne Babenhauserheide
  0 siblings, 1 reply; 3+ messages in thread
From: arne.babenhauserheide @ 2016-05-20 18:07 UTC (permalink / raw)
  To: guile-devel; +Cc: arne_bab

# 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
 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Allow giving floating point values to (sleep).
  2016-05-20 18:07 [PATCH] Allow giving floating point values to (sleep) arne.babenhauserheide
@ 2016-06-26 21:37 ` Arne Babenhauserheide
  2016-06-27  8:10   ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Arne Babenhauserheide @ 2016-06-26 21:37 UTC (permalink / raw)
  To: arne.babenhauserheide; +Cc: arne_bab, guile-devel

[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Allow giving floating point values to (sleep).
  2016-06-26 21:37 ` Arne Babenhauserheide
@ 2016-06-27  8:10   ` Andy Wingo
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2016-06-27  8:10 UTC (permalink / raw)
  To: Arne Babenhauserheide; +Cc: guile-devel, arne.babenhauserheide, 19581

On Sun 26 Jun 2016 23:37, Arne Babenhauserheide <arne_bab@web.de> writes:

> ping?

Let's follow up on bug #19581.

Thanks,

Andy



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-27  8:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-20 18:07 [PATCH] Allow giving floating point values to (sleep) arne.babenhauserheide
2016-06-26 21:37 ` Arne Babenhauserheide
2016-06-27  8:10   ` Andy Wingo

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).