<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Why does UTimeFromTime use FLOOR but ToNTime uses ROUND?<BR>
<BR>
<BR>PROCEDURE ToNTime (n: LONGREAL; VAR ts: Utime.struct_timespec) =<BR> BEGIN<BR> ts.tv_sec := TRUNC(n);<BR> ts.tv_nsec := ROUND((n - FLOAT(ts.tv_sec, LONGREAL)) * 1.0D9);<BR> END ToNTime;<BR>
<BR>
<BR>TYPE UTime = Utime.struct_timeval;<BR>
PROCEDURE UTimeFromTime (time: Time.T): UTime =<BR> VAR floor := FLOOR(time);<BR> BEGIN<BR> RETURN UTime{floor, FLOOR(1.0D6 * (time - FLOAT(floor, LONGREAL)))};<BR> END UTimeFromTime;<BR>
<BR>
<BR>I've changed this code to pass doubles to C and do the conversion<BR>there. To reduce/eliminate use of cloned headers.<BR>
<BR>
<BR>For ROUND I'm using C99:<BR>
<BR>/* C99, very portable */<BR> long lround(double);<BR>long long llround(double);<BR>
<BR>#ifdef __CYGWIN__<BR>#define ROUND lround<BR>#else<BR>#define ROUND llround<BR>#endif<BR>typedef double FloatSeconds, LONGREAL;<BR>typedef struct timeval MicrosecondsStruct_t;<BR>
#define FLOAT(value, type) ((type)value)<BR>#define FLOOR floor<BR>
<BR>
<BR>
static<BR>MicrosecondsStruct_t*<BR>FloatSecondsToNanosecondsStruct(LONGREAL n,<BR> MicrosecondsStruct_t* ts)<BR>{<BR> ts->tv_sec = (time_t)n;<BR> ts->tv_nsec = ROUND((n - FLOAT(ts->tv_sec, LONGREAL)) * 1.0E9);<BR> return ts;<BR>}<BR>
<BR>
<BR>
static<BR>MicrosecondsStruct_t*<BR>FloatSecondsToMicrosecondsStruct(FloatSeconds timeout,<BR> MicrosecondsStruct_t* utime)<BR>{<BR> LONGINT sec = FLOOR(timeout);<BR> utime->tv_sec = (time_t)sec;<BR> utime->tv_usec = (suseconds_t)FLOOR(1.0E6 * (timeout - FLOAT(sec, LONGREAL)));<BR> return utime;<BR>}<BR>
<BR>
<BR>
Just arbitrarily a little more correct in the nano case vs. the micro case?<BR>
Matters little? Would matter more for micro due to lower resolution?<BR>
<BR>
<BR>
Thanks,<BR> - Jay<BR><BR><BR><BR><BR> </body>
</html>