Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/iostream.c

    r5721a6d r6ba0659  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb  1 14:20:30 2016
    13 // Update Count     : 60
     12// Last Modified On : Wed Feb 17 14:19:56 2016
     13// Update Count     : 76
    1414//
    1515
     
    1919#include <stdio.h>
    2020#include <string.h>                                                                             // strlen
     21#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2122#include <complex.h>                                                                    // creal, cimag
    2223}
     
    7273ostype * ?|?( ostype *os, double d ) {
    7374        char buffer[32];
    74         return write( os, buffer, sprintf( buffer, "%g", d ) );
     75        return write( os, buffer, sprintf( buffer, "%.*lg", DBL_DIG, d ) );
    7576} // ?|?
    7677
     
    7879ostype * ?|?( ostype *os, long double d ) {
    7980        char buffer[32];
    80         return write( os, buffer, sprintf( buffer, "%Lg", d ) );
     81        return write( os, buffer, sprintf( buffer, "%.*Lg", LDBL_DIG, d ) );
    8182} // ?|?
    8283
     
    110111forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) )
    111112retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
    112   return manip(os);
     113  return manip( os );
    113114}
    114115
    115116forall( dtype ostype | ostream( ostype ) )
    116117ostype * endl( ostype * os ) {
    117   os | "\n";
    118   // flush
    119   return os;
     118        os | "\n";
     119        flush( os );
     120        return os;
    120121} // endl
    121122
    122 forall( type elt_type | writeable( elt_type ),
    123                 type iterator_type | iterator( iterator_type, elt_type ),
     123//---------------------------------------
     124
     125forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
    124126                dtype os_type | ostream( os_type ) )
    125127void write( iterator_type begin, iterator_type end, os_type *os ) {
    126         void print( elt_type i ) {
    127                 os | i | ' ';
    128         }
     128        void print( elt_type i ) { os | i | ' '; }
    129129        for_each( begin, end, print );
    130130} // ?|?
    131131
    132 forall( type elt_type | writeable( elt_type ),
    133                 type iterator_type | iterator( iterator_type, elt_type ),
     132forall( type elt_type | writeable( elt_type ), type iterator_type | iterator( iterator_type, elt_type ),
    134133                dtype os_type | ostream( os_type ) )
    135134void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
     
    138137} // ?|?
    139138
     139//---------------------------------------
    140140
    141141forall( dtype istype | istream( istype ) )
     
    146146forall( dtype istype | istream( istype ) )
    147147istype * ?|?( istype *is, int *ip ) {
    148         char cur;
    149  
    150         // skip some whitespace
    151         do {
    152                 is | &cur;
    153                 if ( fail( is ) || eof( is ) ) return is;
    154         } while ( !( cur >= '0' && cur <= '9' ) );
    155  
    156         // accumulate digits
    157         *ip = 0;
    158         while ( cur >= '0' && cur <= '9' ) {
    159                 *ip = *ip * 10 + ( cur - '0' );
    160                 is | &cur;
    161                 if ( fail( is ) || eof( is ) ) return is;
    162         }
    163  
    164         unread( is, cur );
    165         return is;
     148        return get( is, ip );
    166149} // ?|?
    167150
Note: See TracChangeset for help on using the changeset viewer.