Integer arithmetic problem



I am not sure if it is me or our bellowed "expr" command, but I need
someone to set me straight.

In C the command:
printf("%d\n", -4/3);
gives: -1

I searched c.l.tcl and found a post from 1/27 2005 which said:
set tcl_precision 17 ;# Expressly: to show imperfections with real numbers!
expr {4/3} ==> 1
expr {4/-3} ==> -1

BUT, when I do it in tclsh itself:
expr {-4/3} or expr {4/-3} gives -2 ???

Has someone messed up with integer arithmetic in recent
versions of tcl (I am running 8.4.14)
Just tried on the older version 8.4p1 on different OS/CPU type and got
the same.

Now this is not an academic pursuit.
I was coding a data translator and documentation was
giving a particular expresion to be calculated as
integer arithmetic and I was getting wrong answers.

Anyone has a clue as to what is going on.
I haven't looked at the src yet, but it may get there :-) .

Thanks,
Nikola

.



Relevant Pages