Conversation
Passing null as the tz argument to gettimeofday on Linux is the current recommendation. It also eleminates the compiler "unused tz" error.
| if (stat != 0) | ||
| cloog_msg(NULL, CLOOG_WARNING, "Error return from gettimeofday: %d", stat); | ||
| return (Tp.tv_sec + Tp.tv_usec*1.0e-6); | ||
| return (Tp.tv_sec + Tp.tv_usec/1.0e-6); |
There was a problem hiding this comment.
This does not seem correct: dividing the number of microseconds by 1E-6 is equivalent to multiplying it by 1E6 (1 million). Given that tc_usec is an integer, and that the function returns the number of seconds as double, I reckon we indeed want to multiply microseconds by 1E-6.
There was a problem hiding this comment.
The field is an integer number of microseconds, the intent is to represent that as a fraction of a second (the field is never enough microseconds to represent a full second or more).
Let's try this the easy way, by hand:
Put a 1 dollar bill on table to your left.
Put 99 pennies on table to your right.
How many dollars do you have on the table? (1.99 or 9901.00)
Did you multiple or divide the number of pennies by a 100 to get the fraction of that dollar?
There was a problem hiding this comment.
So the change required is to cast the numbers to double before doing the math.
Otherwise the integer operation will truncate the faction of a second.
There was a problem hiding this comment.
Note that we multiply by one millionth here, not by one million. e-6 means negative power, equivalent to 0.000001 in this case. In your words, we multiplied pennies by 0.01...
We could indeed divide by one million, but there is no point in changing the code that is correct.
There was a problem hiding this comment.
As for types, multiplication has precedence so Tp.tv_usec*1.0e-6 is performed first. It implicitly converts to double as the type of the RHS is a double literal. Then, before addition, the Tp.tv_sec also implicitly converts to double because its RHS is now double.
Remove unused tz structure.
Eliminate "unused variable" compiler error.