1  /* Macro to print floating point numbers in hexadecimal notation.
       2     Copyright (C) 2017-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #define PRINT_FPHEX(FLOAT, VAR, IEEE854_UNION, IEEE854_BIAS)		      \
      20  do {									      \
      21        /* We have 112 bits of mantissa plus one implicit digit.  Since	      \
      22  	 112 bits are representable without rest using hexadecimal	      \
      23  	 digits we use only the implicit digits for the number before	      \
      24  	 the decimal point.  */						      \
      25        unsigned long long int num0, num1;				      \
      26        union IEEE854_UNION u;						      \
      27        u.d = VAR;							      \
      28  									      \
      29        assert (sizeof (FLOAT) == 16);					      \
      30  									      \
      31        num0 = (((unsigned long long int) u.ieee.mantissa0) << 32		      \
      32  	     | u.ieee.mantissa1);					      \
      33        num1 = (((unsigned long long int) u.ieee.mantissa2) << 32		      \
      34  	     | u.ieee.mantissa3);					      \
      35  									      \
      36        zero_mantissa = (num0|num1) == 0;					      \
      37  									      \
      38        if (sizeof (unsigned long int) > 6)				      \
      39  	numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16,		      \
      40  			     info->spec == 'A');			      \
      41        else								      \
      42  	numstr = _itoa (num1, numbuf + sizeof numbuf, 16,		      \
      43  			info->spec == 'A');				      \
      44  									      \
      45        while (numstr > numbuf + (sizeof numbuf - 64 / 4))		      \
      46  	*--numstr = '0';						      \
      47  									      \
      48        if (sizeof (unsigned long int) > 6)				      \
      49  	numstr = _itoa_word (num0, numstr, 16, info->spec == 'A');	      \
      50        else								      \
      51  	numstr = _itoa (num0, numstr, 16, info->spec == 'A');		      \
      52  									      \
      53        /* Fill with zeroes.  */						      \
      54        while (numstr > numbuf + (sizeof numbuf - 112 / 4))		      \
      55  	  *--numstr = '0';						      \
      56  									      \
      57        leading = u.ieee.exponent == 0 ? '0' : '1';			      \
      58  									      \
      59        exponent = u.ieee.exponent;					      \
      60  									      \
      61        if (exponent == 0)						      \
      62  	{								      \
      63  	  if (zero_mantissa)						      \
      64  	    expnegative = 0;						      \
      65  	  else								      \
      66  	    {								      \
      67  	      /* This is a denormalized number.  */			      \
      68  	      expnegative = 1;						      \
      69  	      exponent = IEEE854_BIAS - 1;				      \
      70  	    }								      \
      71  	}								      \
      72        else if (exponent >= IEEE854_BIAS)				      \
      73  	{								      \
      74  	  expnegative = 0;						      \
      75  	  exponent -= IEEE854_BIAS;					      \
      76  	}								      \
      77        else								      \
      78  	{								      \
      79  	  expnegative = 1;						      \
      80  	  exponent = -(exponent - IEEE854_BIAS);			      \
      81  	}								      \
      82  } while (0)