Changeset 09a767e for libcfa/src


Ignore:
Timestamp:
Aug 10, 2023, 10:27:05 PM (10 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
b2ab352
Parents:
13600e8
Message:

fix incorrect location of decimal point for floating-point value in hex, print base (0x) before 0 for hexadecimal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r13600e8 r09a767e  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug  9 10:10:56 2023
    13 // Update Count     : 1432
     12// Last Modified On : Thu Aug 10 18:15:44 2023
     13// Update Count     : 1442
    1414//
    1515
     
    172172                                for ( i; 0 ~ @ ) { \
    173173                                        if ( i == len ) { fmt( os, "." ); break; } \
    174                                         if ( buf[i] == '.' || buf[i] == 'e' || buf[i] == 'E' ) break; /* decimal point or scientific ? */ \
     174                                        if ( buf[i] == '.' || buf[i] == 'e' || buf[i] == 'E' || \
     175                                                 buf[i] == 'p' || buf[i] == 'P' ) break; /* decimal point or scientific ? */ \
    175176                                } /* for */ \
    176177                        } /* if */ \
     
    465466                fmtstr[star] = '%'; \
    466467\
     468                /* Special case printing 0 in hexadecimal as printf does not put the base. */ \
     469                if ( (f.base == 'x' | f.base == 'X') && ! f.flags.nobsdp && f.val == 0 ) { \
     470                        fmt( os, f.base == 'x' ? "0x" : "0X" ); \
     471                        f.wd -= 2; \
     472                        if ( f.wd < 0 ) f.wd = 1; \
     473                } /* if */ \
     474\
    467475                if ( ! f.flags.pc ) {                                                   /* no precision */ \
    468476                        fmtstr[sizeof(IFMTNP)-2] = f.base;                      /* sizeof includes '\0' */ \
     
    595603                        len = snprintf( buf, size, format, ##__VA_ARGS__ ); \
    596604                        if ( isfinite( f.val ) && ( f.pc != 0 || ! f.flags.nobsdp ) ) { /* if number, print decimal point when no fraction or exponent */ \
    597                                 for ( i = 0; i < len && buf[i] != '.' && buf[i] != 'e' && buf[i] != 'E'; i += 1 ); /* decimal point or scientific ? */ \
     605                                for ( i = 0; i < len && buf[i] != '.' && buf[i] != 'e' && buf[i] != 'E' && \
     606                                                                 buf[i] != 'p' && buf[i] != 'P'; i += 1 ); /* decimal point or scientific ? */ \
    598607                                if ( i == len ) { \
    599608                                        if ( ! f.flags.left ) { \
Note: See TracChangeset for help on using the changeset viewer.