Skip to main content
Disable syntax highlighting on output
Source Link
toolic
  • 15.8k
  • 6
  • 29
  • 217
overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: 
ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: 
constants available at compile time: 
ULONG_MAX + ( ULONG_MAX/2 ) :  9223372036854775806 
 error occured: Success
one value read at runtime: 
ULONG_MAX + argv-09         :  9223372036854775806 
 error occured: Success
similar val. from conversion: 
known at compile time       :  18446744073709551615 
 error occured: Success
one value read at runtime   :  0 
 error occured: Success
three different results for calculations which mathematical, user POV, should be the same.  
    overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: 
    ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: 
    constants available at compile time: 
    ULONG_MAX + ( ULONG_MAX/2 ) :  9223372036854775806 
     error occured: Success
    one value read at runtime: 
    ULONG_MAX + argv-09         :  9223372036854775806 
     error occured: Success
    similar val. from conversion: 
    known at compile time       :  18446744073709551615 
     error occured: Success
    one value read at runtime   :  0 
     error occured: Success
    three different results for calculations which mathematical, user POV, should be the same.  
overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: 
ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: 
constants available at compile time: 
ULONG_MAX + ( ULONG_MAX/2 ) :  9223372036854775806 
 error occured: Success
one value read at runtime: 
ULONG_MAX + argv-09         :  9223372036854775806 
 error occured: Success
similar val. from conversion: 
known at compile time       :  18446744073709551615 
 error occured: Success
one value read at runtime   :  0 
 error occured: Success
three different results for calculations which mathematical, user POV, should be the same.  
    overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: 
    ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: 
    constants available at compile time: 
    ULONG_MAX + ( ULONG_MAX/2 ) :  9223372036854775806 
     error occured: Success
    one value read at runtime: 
    ULONG_MAX + argv-09         :  9223372036854775806 
     error occured: Success
    similar val. from conversion: 
    known at compile time       :  18446744073709551615 
     error occured: Success
    one value read at runtime   :  0 
     error occured: Success
    three different results for calculations which mathematical, user POV, should be the same.  
added output.
Source Link
    printf( "overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: \n" ); 
    printf( "ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: \n" ); 
    printf( "constants available at compile time: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + ( ULONG_MAX/2 ) :  %1lu \n", ULONG_MAX + ( ULONG_MAX / 2 ) ); 
    perror( " error occured"); 
    printf( "one value read at runtime: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + argv-09         :  %1lu \n", ULONG_MAX + strtoul( argv[ 9 ], NULL, 0 ) ); 
    perror( " error occured"); 
    printf( "similar val. from conversion: \n" ); 
    errno = 0; 
    printf( "known at compile time       :  %1lu \n", (ulong)( (long double)ULONG_MAX * 1.5l ) ); 
    perror( " error occured"); 
    errno = 0; 
    printf( "one value read at runtime   :  %1lu \n", (ulong)( (long double)ULONG_MAX + (long double)( strtoul( argv[ 9 ], NULL, 0 ) ) ) ); 
    perror( " error occured"); 
    printf( "three different results for calculations which mathematical, user POV, should be the same. \n" ); 
    printf( " \n" );  

which here produces the output:

overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: 
ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: 
constants available at compile time: 
ULONG_MAX + ( ULONG_MAX/2 ) :  9223372036854775806 
 error occured: Success
one value read at runtime: 
ULONG_MAX + argv-09         :  9223372036854775806 
 error occured: Success
similar val. from conversion: 
known at compile time       :  18446744073709551615 
 error occured: Success
one value read at runtime   :  0 
 error occured: Success
three different results for calculations which mathematical, user POV, should be the same.  
    printf( "overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: \n" ); 
    printf( "ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: \n" ); 
    printf( "constants available at compile time: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + ( ULONG_MAX/2 ) :  %1lu \n", ULONG_MAX + ( ULONG_MAX / 2 ) ); 
    perror( " error occured"); 
    printf( "one value read at runtime: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + argv-09         :  %1lu \n", ULONG_MAX + strtoul( argv[ 9 ], NULL, 0 ) ); 
    perror( " error occured"); 
    printf( "similar val. from conversion: \n" ); 
    errno = 0; 
    printf( "known at compile time       :  %1lu \n", (ulong)( (long double)ULONG_MAX * 1.5l ) ); 
    perror( " error occured"); 
    errno = 0; 
    printf( "one value read at runtime   :  %1lu \n", (ulong)( (long double)ULONG_MAX + (long double)( strtoul( argv[ 9 ], NULL, 0 ) ) ) ); 
    perror( " error occured"); 
    printf( "three different results for calculations which mathematical, user POV, should be the same. \n" ); 
    printf( " \n" ); 
    printf( "overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: \n" ); 
    printf( "ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: \n" ); 
    printf( "constants available at compile time: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + ( ULONG_MAX/2 ) :  %1lu \n", ULONG_MAX + ( ULONG_MAX / 2 ) ); 
    perror( " error occured"); 
    printf( "one value read at runtime: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + argv-09         :  %1lu \n", ULONG_MAX + strtoul( argv[ 9 ], NULL, 0 ) ); 
    perror( " error occured"); 
    printf( "similar val. from conversion: \n" ); 
    errno = 0; 
    printf( "known at compile time       :  %1lu \n", (ulong)( (long double)ULONG_MAX * 1.5l ) ); 
    perror( " error occured"); 
    errno = 0; 
    printf( "one value read at runtime   :  %1lu \n", (ulong)( (long double)ULONG_MAX + (long double)( strtoul( argv[ 9 ], NULL, 0 ) ) ) ); 
    perror( " error occured"); 
    printf( "three different results for calculations which mathematical, user POV, should be the same. \n" ); 
    printf( " \n" );  

which here produces the output:

overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: 
ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: 
constants available at compile time: 
ULONG_MAX + ( ULONG_MAX/2 ) :  9223372036854775806 
 error occured: Success
one value read at runtime: 
ULONG_MAX + argv-09         :  9223372036854775806 
 error occured: Success
similar val. from conversion: 
known at compile time       :  18446744073709551615 
 error occured: Success
one value read at runtime   :  0 
 error occured: Success
three different results for calculations which mathematical, user POV, should be the same.  
Source Link

This isn't a full answer, only a snippet too long for a comment.
It demonstrates the behavior of 'wrap' which @chux mentioned as
'well documented'.
However I consider it 'historically grown', not consistently implemented, neither for different calculations with integers nor in sync with other - e.g. binary - computer datatypes, mathematically wrong and 'user trapping'.
See three different results for a function which mathematically should calculate the same, see none of them raising / setting errno.
It' probably similar for uint128, I took unsigned long for the demo as it's
better matured than 128-bit values.

    printf( "overflow handling of unsigned long integers, call with argv-9 = 9223372036854775807: \n" ); 
    printf( "ULONG_MAX + ( ULONG_MAX / 2 ), different calculations: \n" ); 
    printf( "constants available at compile time: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + ( ULONG_MAX/2 ) :  %1lu \n", ULONG_MAX + ( ULONG_MAX / 2 ) ); 
    perror( " error occured"); 
    printf( "one value read at runtime: \n" ); 
    errno = 0; 
    printf( "ULONG_MAX + argv-09         :  %1lu \n", ULONG_MAX + strtoul( argv[ 9 ], NULL, 0 ) ); 
    perror( " error occured"); 
    printf( "similar val. from conversion: \n" ); 
    errno = 0; 
    printf( "known at compile time       :  %1lu \n", (ulong)( (long double)ULONG_MAX * 1.5l ) ); 
    perror( " error occured"); 
    errno = 0; 
    printf( "one value read at runtime   :  %1lu \n", (ulong)( (long double)ULONG_MAX + (long double)( strtoul( argv[ 9 ], NULL, 0 ) ) ) ); 
    perror( " error occured"); 
    printf( "three different results for calculations which mathematical, user POV, should be the same. \n" ); 
    printf( " \n" );