From: Maarten Kronenburg (M.Kronenburg_at_[hidden])
Date: 2006-05-31 09:37:47
Because the integer binary operators
must clone the rhs OR the lhs,
the temporaries in expressions can be
of type integer OR derived type.
Now as each derived type has an
operator=( const integer & )
which turns the integer temporary
back to the derived type,
the result after assignment is always
But the temporaries can still be either
integer type or derived type.
can have another type of temporary then
However which type it is is independent
of compiler, because of the
Now the question is that because
unsigned_integer throws an exception
when it becomes negative,
is it acceptable that when a and b nonzero,
then throws an exception and
"Maarten Kronenburg" <M.Kronenburg_at_[hidden]> wrote in message
> There is however one catch to the
> unsigned_integer: the expression
> Then look in [expr.add]:
> "The additive operators group from
> The integer binary operator-
> first clones the rhs, negates it,
> and then adds to it the lhs.
> This guarantees that when b or c
> are non-zero unsigned_integer,
> then ALWAYS an exception
> is thrown.
> BUT what about
> Now (b+c) returns a temporary
> integer (not unsigned_integer),
> which is negated (NO exception)
> and a is added to it.
> So although the behaviour is
> compiler-independent because of the
> [expr.add] remark, the use of braces
> in expressions may change the
> behaviour of an unsigned_integer
> expression, that is while
> may throw an exception,
> may not.
> Regards, Maarten.
> "Maarten Kronenburg" <M.Kronenburg_at_[hidden]> wrote in message
> > If you don't mind I start a new thread here.
> > The unsigned infinite precision integer is
> > different from the base type unsigned int,
> > which is actually a modular integer with
> > modulus 2^n.
> > Therefore two integer derived classes are
> > needed: unsigned_integer and modular_integer.
> > The unsigned_integer is an infinite precision
> > integer which can only be positive or zero.
> > The negate() of a non-zero unsigned_integer
> > will always throw an exception.
> > A subtraction which results in a negative value
> > will do the same; therefore in my opinion
> > there is no fundamental problem with this,
> > as negation is subtraction from zero.
> > The modular_integer has a static method
> > static void set_modulus( const integer & ).
> > When the modulus is not set, it is zero,
> > in that case the modular_integer is identical to integer.
> > Users that like an unsigned integer with
> > a negate() that always works, will have to
> > use a modular_integer and set its modulus
> > to a positive value.
> > In the document I will specify unsigned_integer
> > and modular_integer, and thus implementations
> > can provide them.
> > Regards, Maarten.
> > _______________________________________________
> > Unsubscribe & other changes:
> Unsubscribe & other changes:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk