NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

RE: bin/59749: awk bad test to see if printf supports the %a format



The following reply was made to PR bin/59749; it has been noted by GNATS.

From: <trevor.zacks%btopenworld.com@localhost>
To: <gnats-bugs%netbsd.org@localhost>
Cc: 
Subject: RE: bin/59749: awk bad test to see if printf supports the %a format
Date: Thu, 6 Nov 2025 15:33:49 -0000

 Hi,
 	I tested with
 
 #include <stdio.h>
 #include <stdlib.h>
 
 /* awk run.c format() */
 
 int main( int argc, char *argv[], char *envp[] )
 {
     int have_a_format = 0;
 
     char xbuf[100];
 
     snprintf( xbuf, sizeof( xbuf ), "%a", 42.0 );
     have_a_format = ( strcmp( xbuf, "0x1.5p+5" ) == 0 );
 
     printf( "xbuf:%s:   have_a_format:%d\n", xbuf, have_a_format );
 
     snprintf( xbuf, sizeof( xbuf ), "%.1a", 42.0 );
     have_a_format = ( strcmp( xbuf, "0x1.5p+5" ) == 0 );
 
     printf( "xbuf:%s:   have_a_format:%d\n", xbuf, have_a_format );
 
     return 0;
 }
 
 And got the output
 
 xbuf:0x1.5000000000000p+5:   have_a_format:0
 xbuf:0x1.5p+5:   have_a_format:1
 
 so "%.1a" is correct (for me)
 
 Enjoy
 
 -----Original Message-----
 From: Christos Zoulas via gnats <gnats-admin%NetBSD.org@localhost> 
 Sent: 06 November 2025 14:45
 To: gnats-admin%netbsd.org@localhost; netbsd-bugs%netbsd.org@localhost;
 trevor.zacks%btopenworld.com@localhost
 Subject: Re: bin/59749: awk bad test to see if printf supports the %a format
 
 The following reply was made to PR bin/59749; it has been noted by GNATS.
 
 From: Christos Zoulas <christos%zoulas.com@localhost>
 To: gnats-bugs%netbsd.org@localhost
 Cc: gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
 Subject: Re: bin/59749: awk bad test to see if printf supports the %a format
 Date: Thu, 06 Nov 2025 09:44:07 -0500
 
  On 2025-11-06 8:35 am, trevor.zacks%btopenworld.com@localhost wrote:
  
  > Will never match "0x1.5p+5" unless the default printf() precision is 1
  
  I don't understand this statement; there precision in printf(3) is fixed
 by the c standard and baked into libc. This program:
  
  #include <stdio.h>
  
  int
  main(void)
  {
           char xbuf[100];
           snprintf(xbuf, sizeof(xbuf), "%a", 42.0);
           printf("%s\n", xbuf);
           return 0;
  }
  
  prints 0x1.5p+5, so the code as is in awk works?
  
  christos
  
 


Home | Main Index | Thread Index | Old Index