Changeset 3c5dee4 for libcfa


Ignore:
Timestamp:
May 16, 2019, 9:41:39 AM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
553772b
Parents:
5cb2b8c
Message:

change istype nl to ignore characters to newline, change ostype to print a decimal point for floating points

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r5cb2b8c r3c5dee4  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 20 14:02:43 2019
    13 // Update Count     : 617
     12// Last Modified On : Mon May 13 12:46:45 2019
     13// Update Count     : 650
    1414//
    1515
     
    2323extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
    2424#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
     25#include <math.h>                                                                               // modff, modf, modlf
    2526#include <complex.h>                                                                    // creal, cimag
    2627}
     
    156157                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    157158                fmt( os, "%g", f );
     159                float tempi;
     160                if ( isfinite( f ) && modff( f, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point
    158161                return os;
    159162        } // ?|?
     
    165168                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    166169                fmt( os, "%.*lg", DBL_DIG, d );
     170                // fmt( os, "%lg", d );
     171                double tempi;
     172                if ( isfinite( d ) && modf( d, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point
    167173                return os;
    168174        } // ?|?
     
    174180                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    175181                fmt( os, "%.*Lg", LDBL_DIG, ld );
     182                // fmt( os, "%Lg", ld );
     183                long double tempi;
     184                if ( isfinite( ld ) && modfl( ld, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point
    176185                return os;
    177186        } // ?|?
     
    182191        ostype & ?|?( ostype & os, float _Complex fc ) {
    183192                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    184                 fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) );
     193                float temp = crealf( fc ), tempi;
     194                fmt( os, "%g", temp );
     195                if ( isfinite( temp ) && modff( temp, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point
     196                temp = cimagf( fc );
     197                fmt( os, "%+g", temp );
     198                if ( isfinite( temp ) && modff( temp, &tempi ) == 0.0F ) fmt( os, "." ); // always print decimal point
     199                fmt( os, "i" );
    185200                return os;
    186201        } // ?|?
     
    191206        ostype & ?|?( ostype & os, double _Complex dc ) {
    192207                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    193                 fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) );
     208                double temp = creal( dc ), tempi;
     209                fmt( os, "%.*lg", DBL_DIG, temp );
     210                if ( isfinite( temp ) && modf( temp, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point
     211                temp = cimag( dc );
     212                fmt( os, "%+.*lg", DBL_DIG, temp );
     213                if ( isfinite( temp ) && modf( temp, &tempi ) == 0.0D ) fmt( os, "." ); // always print decimal point
     214                fmt( os, "i" );
     215                // fmt( os, "%lg%+lgi", creal( dc ), cimag( dc ) );
    194216                return os;
    195217        } // ?|?
     
    200222        ostype & ?|?( ostype & os, long double _Complex ldc ) {
    201223                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    202                 fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
     224                long double temp = creall( ldc ), tempi;
     225                fmt( os, "%.*Lg", LDBL_DIG, temp );
     226                if ( isfinite( temp ) && modfl( temp, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point
     227                temp = cimagl( ldc );
     228                fmt( os, "%+.*Lg", LDBL_DIG, cimagl( ldc ) );
     229                if ( isfinite( temp ) && modfl( temp, &tempi ) == 0.0L ) fmt( os, "." ); // always print decimal point
     230                fmt( os, "i" );
     231                // fmt( os, "%Lg%+Lgi", creall( ldc ), cimagl( ldc ) );
    203232                return os;
    204233        } // ?|?
     
    494523        } // ?|?
    495524
    496 
    497525        // manipulators
    498526        istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
     
    501529
    502530        istype & nl( istype & is ) {
    503                 fmt( is, "%*[ \t\f\n\r\v]" );                                   // ignore whitespace
     531                fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
    504532                return is;
    505533        } // nl
  • libcfa/src/iostream.hfa

    r5cb2b8c r3c5dee4  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri May  3 22:55:04 2019
    13 // Update Count     : 230
     12// Last Modified On : Sat May 11 10:31:27 2019
     13// Update Count     : 232
    1414//
    1515
     
    190190
    191191        // manipulators
     192        istype & ?|?( istype &, istype & (*)( istype & ) );
     193        istype & nl( istype & is );
    192194        istype & nlOn( istype & );
    193195        istype & nlOff( istype & );
    194         istype & ?|?( istype &, istype & (*)( istype & ) );
    195         istype & nl( istype & is );
    196196} // distribution
    197197
     
    215215
    216216// Local Variables: //
    217 // mode: c //
    218217// tab-width: 4 //
    219218// End: //
Note: See TracChangeset for help on using the changeset viewer.