Boost logo

Boost :

From: David Bergman (davidb_at_[hidden])
Date: 2002-08-22 13:58:47


Although "(unsigned int)a * (unsigned int)b == a * b" needs not hold for
all postitive a and b being "int", the subset of positive "int" still
have to be a subset of "unsigned int". And since every subexpression in
a full expression needs to have a type, what type does "a*b" in "a*b/c"
have, where a, b and c are all "int"?

If "a*b" is an "int", then we cannot use the "overflow and back again"
trick.

Or, can we wait with proper typing till we reach sequence point in the
execution (which in this case would be after the evaluation of the full
expression)?

/David

-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Bill Seymour
Sent: Thursday, August 22, 2002 1:55 PM
To: boost_at_[hidden]
Subject: [boost] Re: (boost) Re: A pure C/C++ question

Victor A. Wagner wrote:
>
> I'm one of those weirdos that thinks that "correct" is
> a lot more important than "fast".
>

Perhaps in your application domain. Folk who write,
e.g., encryption routines would disagree. They need
arithmetic to be fast and repeatable (gets the same
answer every time). Whether it gets the "correct"
answer is totally irrelevant.

David Bergman wrote:
>
> [Integer] arithmetic is supposed to be module 2^n, ...
>

No, just unsigned integer arithmetic. As others have
already said, signed integer overflow yields undefined behavior. That
includes, but is not limited to, wrapping modulo 2^n as if it were
unsigned (MSVC and others), INT_MAX + 1 == 1 (Borland, IIRC), hardware
traps (Unisys, Cray, IIRC), ...

--Bill Seymour
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk