https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69088

--- Comment #2 from BENAÏSSA <ka_bena at yahoo dot fr> ---
/*
thank you for your answer.
     A.Benaïssa
Comment:
  Please consider this case:     
*/

#include <stdio.h>         
int main()
{         
  float A = 0.F      ;
  _Bool              B1  = 1.F / A ;
  signed char        B2  = 1.F / A ;
  unsigned char      B3  = 1.F / A ;
  signed short       B4  = 1.F / A ;
  unsigned short     B5  = 1.F / A ;
  signed int         B6  = 1.F / A ;
  unsigned int       B7  = 1.F / A ;
  signed long        B8  = 1.F / A ;
  unsigned long      B9  = 1.F / A ;
  signed long long   B10 = 1.F / A ;
  unsigned long long B11 = 1.F / A ;

  double C = 0.      ;
  _Bool              D1  = 1. / C ;
  signed char        D2  = 1. / C ;
  unsigned char      D3  = 1. / C ;
  signed short       D4  = 1. / C ;
  unsigned short     D5  = 1. / C ;
  signed int         D6  = 1. / C ;
  unsigned int       D7  = 1. / C ;
  signed long        D8  = 1. / C ;
  unsigned long      D9  = 1. / C ;
  signed long long   D10 = 1. / C ;
  unsigned long long D11 = 1. / C ;

  long double E = 0.L      ;
  _Bool              F1  = 1.L / E ;
  signed char        F2  = 1.L / E ;
  unsigned char      F3  = 1.L / E ;
  signed short       F4  = 1.L / E ;
  unsigned short     F5  = 1.L / E ;
  signed int         F6  = 1.L / E ;
  unsigned int       F7  = 1.L / E ;
  signed long        F8  = 1.L / E ;
  unsigned long      F9  = 1.L / E ;
  signed long long   F10 = 1.L / E ;
  unsigned long long F11 = 1.L / E ;

  __float128 G = 0.Q      ;
  _Bool              H1  = 1.Q / G ;
  signed char        H2  = 1.Q / G ;
  unsigned char      H3  = 1.Q / G ;
  signed short       H4  = 1.Q / G ;
  unsigned short     H5  = 1.Q / G ;
  signed int         H6  = 1.Q / G ;
  unsigned int       H7  = 1.Q / G ;
  signed long        H8  = 1.Q / G ;
  unsigned long      H9  = 1.Q / G ;
  signed long long   H10 = 1.Q / G ;
  unsigned long long H11 = 1.Q / G ;

  printf("_Bool\n") ;
  printf("  B1 = %d \n" , B1) ;
  printf("  D1 = %d \n" , D1) ;
  printf("  F1 = %d \n" , F1) ;
  printf("  H1 = %d \n" , H1) ;
  printf("char signed\n") ;
  printf("  B2 = %d \n" , (int)B2) ;
  printf("  D2 = %d \n" , (int)D2) ;
  printf("  F2 = %d \n" , (int)F2) ;
  printf("  H2 = %d \n" , (int)H2) ;
  printf("char unsigned\n") ;
  printf("  B3 = %u \n" , (int unsigned)B3) ;
  printf("  D3 = %u \n" , (int unsigned)D3) ;
  printf("  F3 = %u \n" , (int unsigned)F3) ;
  printf("  H3 = %u \n" , (int unsigned)H3) ;
  printf("short signed\n") ;
  printf("  B4 = %hd \n" , B4) ;
  printf("  D4 = %hd \n" , D4) ;
  printf("  F4 = %hd \n" , F4) ;
  printf("  H4 = %hd \n" , H4) ;
  printf("short unsigned\n") ;
  printf("  B5 = %hu \n" , B5) ;
  printf("  D5 = %hu \n" , D5) ;
  printf("  F5 = %hu \n" , F5) ;
  printf("  H5 = %hu \n" , H5) ;
  printf("int signed\n") ;
  printf("  B6 = %d \n" , B6) ;
  printf("  D6 = %d \n" , D6) ;
  printf("  F6 = %d \n" , F6) ;
  printf("  H6 = %d \n" , H6) ;
  printf("int unsigned\n") ;
  printf("  B7 = %u \n" , B7) ;
  printf("  D7 = %u \n" , D7) ;
  printf("  F7 = %u \n" , F7) ;
  printf("  H7 = %u \n" , H7) ;
  printf("long\n") ;
  printf("  B8 = %d \n" , B8) ;
  printf("  D8 = %d \n" , D8) ;
  printf("  F8 = %d \n" , F8) ;
  printf("  H8 = %d \n" , H8) ;
  printf("long unsigned \n") ;
  printf("  B9 = %lu \n" , B9) ;
  printf("  D9 = %lu \n" , D9) ;
  printf("  F9 = %lu \n" , F9) ;
  printf("  H9 = %lu \n" , H9) ;
  printf("long long \n") ;
  printf("  B10 = %lld \n" , B10) ;
  printf("  D10 = %lld \n" , D10) ;
  printf("  F10 = %lld \n" , F10) ;
  printf("  H10 = %lld \n" , H10) ;
  printf("long long unsigned\n") ;
  printf("  B11 = %llu \n" , B11) ;
  printf("  D11 = %llu \n" , D11) ;
  printf("  F11 = %llu \n" , F11) ;
  printf("  H11 = %llu \n" , H11) ;

return 0;
}
/*
RESULTS::

_Bool
  B1 = 1 
  D1 = 1 
  F1 = 1 
  H1 = 1 
char signed
  B2 = 0 
  D2 = 0 
  F2 = 0 
  H2 = -1 
char unsigned
  B3 = 0 
  D3 = 0 
  F3 = 0 
  H3 = 0 
short signed
  B4 = -32768 
  D4 = -32768 
  F4 = -32768 
  H4 = -1 
short unsigned
  B5 = 0 
  D5 = 0 
  F5 = 0 
  H5 = 0 
int signed
  B6 = -2147483648 
  D6 = -2147483648 
  F6 = -2147483648 
  H6 = 2147483647 
int unsigned
  B7 = 0 
  D7 = 0 
  F7 = 0 
  H7 = 0 
long
  B8 = -2147483648 
  D8 = -2147483648 
  F8 = -2147483648 
  H8 = 2147483647 
long unsigned 
  B9 = 0 
  D9 = 0 
  F9 = 0 
  H9 = 0 
long long 
  B10 = -9223372036854775808 
  D10 = -9223372036854775808 
  F10 = -9223372036854775808 
  H10 = 9223372036854775807 
long long unsigned
  B11 = 0 
  D11 = 0 
  F11 = 0 
  H11 = 0 

it is clear that there is no real infinite value for any floating 
point representation but instead there is a symbolic representation
of infinites values by a finite sequence of bits.
This finite sequence of bits allows us to create a simple algebra 
on infinite's.
The type conversion from valid floating values to integer values is 
always possible in C.
This not means that for "infinites floating point values" , the result
of type conversion from real to integer is a valid algebraic value.
Instead, it seems that the rules determining the result of type 
conversion is simple (except for _Bool and signed char) as the 
prededing results suggest:
1-for signed we obtain the minimum value of the integer signed type
2-for unsigned we obtain 0 for integer unsigned type
I imagine that this simple rule was forgotten or omitted for some 
reasons for __float128.
I would notice that when you speak about undefined behaviour you means possibly 
that the result of conversion is not a valid algebraic value.
*/


    Le Mercredi 30 décembre 2015 17h56, "sch...@linux-m68k.org"
<gcc-bugzi...@gcc.gnu.org> a écrit :


 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69088

Andreas Schwab <sch...@linux-m68k.org> changed:

          What    |Removed                    |Added
----------------------------------------------------------------------------
            Status|UNCONFIRMED                |RESOLVED
        Resolution|---                        |INVALID

--- Comment #1 from Andreas Schwab <sch...@linux-m68k.org> ---
Inf is not a finite value in the range of int, thus the conversion invokes
undefined behaviour.

Reply via email to