[Bug other/60843] Documentation: 4.5 Integers/C99 6.3.1.3 (reduce modulo 2^N)

2014-04-30 Thread joseph at codesourcery dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60843

--- Comment #3 from joseph at codesourcery dot com joseph at codesourcery dot 
com ---
On Wed, 30 Apr 2014, kdevel at vogtner dot de wrote:

 The problem is the erroneous wording reduction modulo 2^N. *Reduction* by
 definition results in the least *nonnegative* number out of the list of
 congruent numbers, cf. http://www.youtube.com/watch?v=SO6l6sDwEFgt=5m50s

It's perfectly normal English usage for X with qualifier to be outside 
what would be understood by X without the qualifier.  I think the use in 
the GCC manual is a perfectly ordinary and well-understood use of the 
term.  The GCC manual is not trying to refer to any particular set of 
definitions as normative references, and it's not trying to give formal 
definitions.

If anything, I'd say strictly reduction modulo 2^N is a map from Z to Z / 
2^N Z, i.e. producing an equivalence class of integers rather than a 
single integer (and for modulo arithmetic, integer types are interpreted 
as having values that are such equivalence classes).


[Bug other/60843] Documentation: 4.5 Integers/C99 6.3.1.3 (reduce modulo 2^N)

2014-04-29 Thread joseph at codesourcery dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60843

--- Comment #1 from joseph at codesourcery dot com joseph at codesourcery dot 
com ---
On Tue, 15 Apr 2014, kdevel at vogtner dot de wrote:

 For conversion to a type of width N, the value is reduced modulo 2^N to be
 within range of the type; no signal is raised.
 
 Reduce A modulo M usually means find the least integer R in the range [0, M -
 1] such that A is congruent R modulo M. But this is not what gcc compiled

I don't see the problem.  It explicitly says reduced modulo 2^N to be 
within range of the type, and that unambiguously defines the result 
value, as there is exactly one result within the range of the type that is 
equal to the input, modulo 2^N.  The qualifier to be within range of the 
type says that [0, M - 1] is irrelevant, because that isn't the range of 
the type in question.

This is the normal form of modulo arithmetic for signed types, as used for 
example by -fwrapv (and defined in detail in the first (1994) edition of 
LIA-1; the second (2012) edition removes the modulo operations, but the 
underlying wrap_I operation is in LIA-2).