Re: Bug in expr ?



tunity5@xxxxxxxxx schrieb:
stephanearnold@xxxxxxxx wrote:
Hi,

IMHO there is no relation with floats. It is the rule that, given A & B
positive,
(A modulo B) and (-A modulo B) cannot be negative. (it is a convention)


I don't follow you wrote.

Perhaps, I can provide some background into how I came across this
behavior:


########## find out how many days between any two dates
########## specifically, number of 24-hour spans between them
######### set up
set one_day [expr 60 * 60 * 24]
set today [clock seconds]
set yesterday [clock scan "july 2, 2006"]

#### ordering #1
% expr ($today - $yesterday) / $one_day
0


#### ordering #2
% expr ($yesterday - $today) / $one_day
-1

So, the question is, what is the answer? Note that I am OK with either
answer (0 or 1), depending on what you view as a "day" but I would like
to get the same result from both expressions.

So use floating point arithmetics and force rounding in a way you like.

Michael
.



Relevant Pages

  • Re: Bug in expr ?
    ... IMHO there is no relation with floats. ... and (-A modulo B) cannot be negative. ... depending on what you view as a "day" but I would like ... to get the same result from both expressions. ...
    (comp.lang.tcl)
  • Re: Bug in expr ?
    ... IMHO there is no relation with floats. ... and (-A modulo B) cannot be negative. ... This rule must also be implemented in arbitrary precision arithmetics. ... (math::bignum in tcllib) ...
    (comp.lang.tcl)