On 2/3/26 11:48 AM, Harald Anlauf wrote:
Hi Jerry!

On 2/2/26 22:42, Jerry D wrote:
On 2/2/26 12:28 PM, Harald Anlauf wrote:
Hi Jerry!

--- snip ---
Let's see:

13.7.2.3.6 EX editing

The EXw.d and EXw.dEe edit descriptors indicate that the external field
occupies w positions, except when w is zero in which case the processor
selects the field width. The fractional part of the field contains d
hexadecimal digits, except when d is zero in which case the processor
selects the number of hexadecimal digits to be the minimum required so
that the output field is equal to the internal value; ...

But -0XF.FFFFFP+124 is shorter than -0X1.FFFFFEP+127, so I think
you should recheck.  Sorry for the extra work ;-)



I am very aware of this. My interpretation is "in which case the processor
selects" the number of hexadecimal digits to be what ever minimum it chooses
to produce. Keep in mind this is using the built-in C functions to generate
the hex string so we do not have a bit string to deal with. The value is correct and it is the minimum the processor produces.

Anyone else one to way in on this? I sure don't want to create custom code bit shift this.

Not sure if C is really a good reference.
printf takes a double when one wants to pass a float.
With 53 bits for a double with the leading one implicitly set
one could be biased towards a leading 1 before the decimal point.

#include <stdio.h>
#include <values.h>

int
main()
{
   printf ("%A\n", -FLT_MAX);
   printf ("%A\n",-0X1.FFFFFEP+127);
   printf ("%A\n", -0XF.FFFFFP+124);
}

-0X1.FFFFFEP+127
-0X1.FFFFFEP+127
-0X1.FFFFFEP+127

And Fortran does it better (shorter)... ;-)

Harald


I have been researching how best to do this. In the meantime,
for the test cases I am thinking similar to the following:

! { dg-options "-cpp -std=gnu" }
! { dg-do run }
! pr93727 EX Format Specifiers, testing various kinds, default field widths
program main
  implicit none
  character(kind=1, len=48) :: s1
  real(4) :: r4
  real(8) :: r8

#ifdef __GFC_REAL_10__
  real(10) :: r10
#endif
  !real(16) :: r16
  r4 = -huge(1.0_4)
  r8 = -huge( 1.0_8)

#ifdef __GFC_REAL_10__
  r10= -huge(1.0_10)
#endif

  ! KIND=16 will be at a later phase
  !r16 = 1.0_16/3.0_16

  write(s1,"(EX0.0,'<')") r4
  if (s1.ne."-0X1.FFFFFEP+127<") stop 1
  write(s1,"(EX0.0,'<')") r8
  if (s1.ne."-0X1.FFFFFFFFFFFFFP+1023<") stop 2

#ifdef __GFC_REAL_10__
  write(s1,"(EX0.0,'<')") r10
  if (s1.ne."-0XF.FFFFFFFFFFFFFFFP+16380<") stop 3
#endif

  write(s1,"(EX0.0,'<')") 1.0_4/r4
  if (s1.ne."-0X1P-128<") stop 4
  write(s1,"(EX0.0,'<')") 1.0_8/r8
  if (s1.ne."-0X0.4P-1022<") stop 5

#ifdef __GFC_REAL_10__
  write(s1,"(EX0.0,'<')") 1.0_10/r10
  if (s1.ne."-0X2P-16385<") stop 6
#endif

  !write(*,"(EX0.0,'<')" r16
end program main

Reply via email to