Changeset 244335b


Ignore:
Timestamp:
May 4, 2026, 12:11:43 PM (2 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
9375148
Parents:
bb1eabc
Message:

update printing of decimal point in floating-point numbers

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rbb1eabc r244335b  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon May  4 07:19:24 2026
    14 %% Update Count     : 7436
     13%% Last Modified On : Mon May  4 12:09:44 2026
     14%% Update Count     : 7440
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    54055405
    54065406\item
    5407 \Indexc{hex}( integer / floating-point  / character / string )\index{manipulator!hex@©hex©} print value in base 16 preceded by ©0x©/©0X©.
     5407\Indexc{hex}( integer / floating-point / character / string )\index{manipulator!hex@©hex©} print value in base 16 preceded by ©0x©/©0X©.
    54085408\begin{cfa}[belowskip=0pt]
    54095409sout | hex( 0 ) | hex( 27HH ) | hex( 27H ) | hex( 27 ) | hex( 27L );
     
    541254120xe5 0xffe5 0xffffffe5 0xffffffffffffffe5
    54135413sout | hex( 0.0 ) | hex( 27.5F ) | hex( 27.5 ) | hex( 27.5L );
    5414 0x0p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
     54140x0.p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
    54155415sout | hex( -27.5F ) | hex( -27.5 ) | hex( -27.5L );
    54165416-0x1.b8p+4 -0x1.b8p+4 -0xd.cp+1
  • libcfa/src/iostream.cfa

    rbb1eabc r244335b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May  3 22:02:37 2026
    13 // Update Count     : 2271
     12// Last Modified On : Mon May  4 12:00:48 2026
     13// Update Count     : 2310
    1414//
    1515
     
    599599#define SUFFIXES_END (SUFFIXES_START + (int)((sizeof(suffixes) / sizeof(char *) - 1) * 3))
    600600
     601// Float-point numbers without a fraction are always printed with a decimal point to reflect the constant type.
     602// Programmers must explicitly disable printing the decimal point for values with no fraction using manipulator nodp.
     603// printf supports printing the decimal point using flag #. However specifier g is broken with #.
     604//
     605//   printf( "%g %#g %g %#g\n", 4., 4., 4.5, 4.5 );
     606//   4 4.00000 4.5 4.50000
     607//
     608// when # is specified, g incorrectly prints 6 significant digits. As a result, # cannot be used to force printing of
     609// the decimal point. Instead, any missing decimal point is manually added.
     610
    601611#define PRINT_WITH_DP2( os, format, ... ) \
    602612        { \
     
    605615                        if ( isfinite( f.val ) && ! f.flags.nobsdp ) { /* if number, print decimal point when no fraction or exponent */ \
    606616                                for ( i = 0; i < len && buf[i] != '.' && buf[i] != 'e' && buf[i] != 'E' && \
    607                                                          buf[i] != 'p' && buf[i] != 'P'; i += 1 ); /* decimal point or scientific ? */ \
     617                                                buf[i] != 'p' && buf[i] != 'P'; i += 1 ); /* decimal point or scientific ? */ \
    608618                                if ( i == len ) { \
    609619                                        if ( ! f.flags.left ) { \
     
    619629                } else { \
    620630                        int exp10, len2; \
    621                         eng( f.val, f.pc, exp10 );                                      /* changes arguments */ \
     631                        eng( f.val, f.pc, exp10 ); /* changes arguments */ \
    622632                        /* printf( "%g %d %d %d %s\n", f.val, f.wd, f.pc, exp10, format ); */ \
    623633                        if ( ! f.flags.left && f.wd > 1 ) { \
     
    657667\
    658668                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \
    659                 char fmtstr[sizeof(DFMTP) + 8];                                 /* sizeof includes '\0' */ \
     669                char fmtstr[sizeof(DFMTP) + 8]; /* sizeof includes '\0' */ \
    660670                if ( ! f.flags.pc ) memcpy( &fmtstr, DFMTNP, sizeof(DFMTNP) ); \
    661671                else memcpy( &fmtstr, DFMTP, sizeof(DFMTP) ); \
    662                 int star = 5;                                                                   /* position before first '*' */ \
     672                int star = 5; /* position before first '*' */ \
    663673\
    664674                /* Insert flags into spaces before '*', from right to left. */ \
     
    666676                if ( f.flags.sign ) { fmtstr[star] = '+'; star -= 1; } \
    667677                if ( f.flags.pad0 ) { fmtstr[star] = '0'; star -= 1; } \
    668                 fmtstr[star] = '\''; star -= 1;                                 /* locale */ \
     678                if ( f.base == 'f' && f.base == 'F' && f.base == 'g' && f.base == 'G' ) { fmtstr[star] = '\''; star -= 1; }     /* locale only for f andg */ \
     679                else if ( ! f.flags.nobsdp && (f.base == 'a' || f.base == 'A') ) { fmtstr[star] = '#'; star -= 1; } /* hex special case  to get decimal point */ \
    669680                fmtstr[star] = '%'; \
    670681\
    671                 if ( ! f.flags.pc ) {                                                   /* no precision */ \
    672                         fmtstr[sizeof(DFMTNP)-2] = f.base;                      /* sizeof includes '\0' */ \
    673                         /* printf( "%g %d %s\n", f.val, f.wd, &fmtstr[star] ); */ \
     682                if ( ! f.flags.pc ) { /* no precision */ \
     683                        fmtstr[sizeof(DFMTNP)-2] = f.base; /* sizeof includes '\0' */ \
     684                        /* printf( "[%g %c %d %s]\n", f.val, f.base, f.wd, &fmtstr[star] ); */ \
    674685                        PRINT_WITH_DP2( os, &fmtstr[star], f.wd, f.val ) \
    675                 } else {                                                                                /* precision */ \
    676                         fmtstr[sizeof(DFMTP)-2] = f.base;                       /* sizeof includes '\0' */ \
    677                         /* printf( "%g %d %d %s\n", f.val, f.wd, f.pc, &fmtstr[star] ); */ \
     686                } else { /* precision */ \
     687                        fmtstr[sizeof(DFMTP)-2] = f.base; /* sizeof includes '\0' */ \
     688                        /* printf( "[%g %c %d %d %s]\n", f.val, f.base, f.wd, f.pc, &fmtstr[star] ); */ \
    678689                        PRINT_WITH_DP2( os, &fmtstr[star], f.wd, f.pc, f.val ) \
    679690                } /* if */ \
  • tests/io/.expect/manipulatorsOutput2.arm64.txt

    rbb1eabc r244335b  
    660x0 0x1b 0x1b 0x1b 0x1b
    770xe5 0xffe5 0xffffffe5 0xffffffffffffffe5
    8 0x0p+0 0x1.b8p+4 0x1.b8p+4 0x1.b8p+4
     80x0.p+0 0x1.b8p+4 0x1.b8p+4 0x1.b8p+4
    99-0x1.b8p+4 -0x1.b8p+4 -0x1.b8p+4
    10100.000000e+00 2.750000e+01 -2.750000e+01
  • tests/io/.expect/manipulatorsOutput2.x64.txt

    rbb1eabc r244335b  
    660x0 0x1b 0x1b 0x1b 0x1b
    770xe5 0xffe5 0xffffffe5 0xffffffffffffffe5
    8 0x0p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
     80x0.p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
    99-0x1.b8p+4 -0x1.b8p+4 -0xd.cp+1
    10100.000000e+00 2.750000e+01 -2.750000e+01
  • tests/io/.expect/manipulatorsOutput2.x86.txt

    rbb1eabc r244335b  
    660x0 0x1b 0x1b 0x1b 0x1b
    770xe5 0xffe5 0xffffffe5 0xffffffe5
    8 0x0p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
     80x0.p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
    99-0x1.b8p+4 -0x1.b8p+4 -0xd.cp+1
    10100.000000e+00 2.750000e+01 -2.750000e+01
Note: See TracChangeset for help on using the changeset viewer.