A NOTE has been added to this issue. ====================================================================== http://austingroupbugs.net/view.php?id=1108 ====================================================================== Reported By: nsz Assigned To: ====================================================================== Project: 1003.1(2016)/Issue7+TC2 Issue ID: 1108 Category: Base Definitions and Headers Type: Error Severity: Editorial Priority: normal Status: New Name: Szabolcs Nagy Organization: musl libc User Reference: Section: limits.h Page Number: Line Number: Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2016-12-09 17:00 UTC Last Modified: 2018-06-07 16:10 UTC ====================================================================== Summary: LONG_MIN must be <= -2147483648 ======================================================================
---------------------------------------------------------------------- (0004041) geoffclare (manager) - 2018-06-07 16:10 http://austingroupbugs.net/view.php?id=1108#c4041 ---------------------------------------------------------------------- On P280 L9437 replace<blockquote><CX>Maximum Acceptable Value: −2 147 483 647</CX></blockquote>with<blockquote><CX>Maximum Acceptable Value: −2 147 483 648</CX></blockquote> At Line 9443 replace<blockquote>Maximum Acceptable Value: −9 223 372 036 854 775 807</blockquote>with<blockquote><CX>Maximum Acceptable Value: −9 223 372 036 854 775 808</CX></blockquote> At L9452 replace<blockquote>Maximum Acceptable Value: −2 147 483 647</blockquote>with<blockquote><CX>Maximum Acceptable Value: −2 147 483 648</CX></blockquote> At L9467 replace<blockquote>Maximum Acceptable Value: −32 767</blockquote>with<blockquote><CX>Maximum Acceptable Value: −32 768</CX></blockquote> After P282 L9539 (<limits.h>) add a new paragraph:<blockquote>The maximum values for SCHAR_MIN, SHRT_MIN, LONG_MIN and LLONG_MIN differ from the C Standard because POSIX.1 requires two's complement representation for the corresponding integer types. The maximum value for INT_MIN differs both for that reason and because POSIX.1 requires that <b>int</b> has a width of at least 32 bits. See also the RATIONALE section for <stdint.h>.</blockquote> On P282 L9543 (<limits.h>) add <stdint.h> to the SEE ALSO section. On P348 L11817 (<stdint.h>) change:<blockquote>An N-bit signed type has values in the range -2<sup>N-1</sup> or 1-2<sup>N-1</sup> to 2<sup>N-1</sup>-1, while an N-bit unsigned type has values in the range 0 to 2<sup>N</sup>-1</blockquote>with<blockquote>An N-bit signed type in two's complement representation has values in the range -2<sup>N-1</sup> to 2<sup>N-1</sup>-1, while an N-bit unsigned type has values in the range 0 to 2<sup>N</sup>-1. <CX>While the C standard also permits signed integers in sign-magnitude or one's complement form, this standard requires an implementation to use two's complement representation for the standard integer types.</CX> </blockquote> After P349 L11866 add a new paragraph with CX shading:<blockquote>If the representation of any of the standard types <b>short</b>, <b>int</b>, <b>long</b> or <b>long long</b> is not the same as one of the above required types, an <b>int</b><i>N</i><b>_t</b> type with that representation shall be defined along with its <b>uint</b><i>N</i><b>_t</b> counterpart.</blockquote> On P351-352 L11944-11965 (<stdint.h>) change all occurrences of:<blockquote>-1)</blockquote>to:<blockquote>)</blockquote>and add CX shading to the affected text in parentheses. On P352 L11979 (<stdint.h>), change:<blockquote>-65 535</blockquote>to:<blockquote><CX>-65 536</CX></blockquote> On P354 L12040 (<stdint.h>), replace <blockquote>(The POSIX standard explicitly requires 8-bit char and two's-complement arithmetic.)</blockquote>with<blockquote>Since the POSIX.1 standard explicitly requires 8-bit char with two's complement arithmetic, it is easier for application writers if the same two's complement guarantees are extended to all of the other standard integer types. Furthermore, in programming environments with a 32-bit <b>long</b>, some POSIX.1 interfaces, such as <i>mrand48</i>(), cannot be implemented if <b>long</b> does not use a two's complement representation.</blockquote> On P567 L19829 (abs), replace<blockquote>If the result cannot be represented, the behavior is undefined.</blockquote>with<blockquote><CX>If the result cannot be represented, the result shall be {INT_MIN}.</CX></blockquote> On P567 L19838 (abs), replace<blockquote>In two's-complement representation, the absolute value of the negative integer with largest magnitude {INT_MIN} might not be representable.</blockquote>with<blockquote><CX>Since POSIX.1 requires a two's complement representation of <b>int</b>, the absolute value of the negative integer with the largest magnitude {INT_MIN} is not representable; but the rules of negation in two's complement arithmetic ensure that {INT_MIN} is returned.</CX></blockquote> On P1135 L38352 (imaxabs), replace<blockquote>If the result cannot be represented, the behavior is undefined.</blockquote>with<blockquote><CX>If the result cannot be represented, the result shall be {INTMAX_MIN}.</CX></blockquote> On P1135 L38361 (imaxabs), replace<blockquote>The absolute value of the most negative number cannot be represented in two's complement.</blockquote>with<blockquote><CX>Since POSIX.1 requires a two's complement representation of <b>intmax_t</b>, the absolute value of the negative integer with the largest magnitude {INTMAX_MIN} is not representable; but the rules of negation in two's complement arithmetic ensure that {INTMAX_MIN} is returned.</CX></blockquote> On P1232 L41185 (labs), replace<blockquote>If the result cannot be represented, the behavior is undefined.</blockquote>with<blockquote><CX>If the result cannot be represented, the result shall be {LONG_MIN} for <i>labs</i>() or {LLONG_MIN} for <i>llabs</i>() .</CX></blockquote> On P1232 L41195 (labs APPLICATION USAGE), replace<blockquote>None.</blockquote>with<blockquote><CX>Since POSIX.1 requires a two's complement representation of <b>long</b> and <b>long long</b>, the absolute value of the negative integer with the largest magnitude {LONG_MIN} or {LLONG_MIN} is not representable; but the rules of negation in two's complement arithmetic ensure that {LONG_MIN} (for <i>labs()</i>) or {LLONG_MIN} (for <i>llabs()</i>) is returned.</CX></blockquote> On P3115 L104217 (printf), replace<blockquote>twos-complement</blockquote>with<blockquote>two's complement</blockquote> Issue History Date Modified Username Field Change ====================================================================== 2016-12-09 17:00 nsz New Issue 2016-12-09 17:00 nsz Name => Szabolcs Nagy 2016-12-09 17:00 nsz Organization => musl libc 2016-12-09 17:00 nsz Section => limits.h 2016-12-09 18:40 EdSchouten Note Added: 0003512 2016-12-09 22:25 nsz Note Added: 0003513 2018-06-07 16:10 geoffclare Note Added: 0004041 ======================================================================
