Changes in / [29038ef:e182ce3]
- Files:
-
- 15 edited
-
doc/user/user.tex (modified) (9 diffs)
-
src/libcfa/fstream (modified) (3 diffs)
-
src/libcfa/fstream.c (modified) (6 diffs)
-
src/libcfa/gmp (modified) (1 diff)
-
src/libcfa/iostream (modified) (4 diffs)
-
src/libcfa/iostream.c (modified) (6 diffs)
-
src/libcfa/iterator (modified) (2 diffs)
-
src/libcfa/iterator.c (modified) (2 diffs)
-
src/libcfa/limits (modified) (2 diffs)
-
src/libcfa/math (modified) (2 diffs)
-
src/libcfa/rational (modified) (3 diffs)
-
src/libcfa/rational.c (modified) (18 diffs)
-
src/libcfa/stdlib (modified) (2 diffs)
-
src/tests/.expect/io.txt (modified) (4 diffs)
-
src/tests/io.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r29038ef re182ce3 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Fri Jul 7 10:36:39201714 %% Update Count : 25 4713 %% Last Modified On : Sun Jul 2 09:49:56 2017 14 %% Update Count : 2503 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 2450 2450 \end{cfa} 2451 2451 \\ 2452 \begin{cfa}[ showspaces=true,aboveskip=0pt,belowskip=0pt]2452 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2453 2453 1® ®2® ®3 2454 2454 \end{cfa} 2455 2455 & 2456 \begin{cfa}[ showspaces=true,aboveskip=0pt,belowskip=0pt]2456 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2457 2457 1 2 3 2458 2458 \end{cfa} … … 2461 2461 The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators. 2462 2462 Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''. 2463 \begin{cfa} 2464 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6] ];2463 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2464 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ]; 2465 2465 sout | t1 | t2 | endl; §\C{// print tuples}§ 2466 2466 \end{cfa} 2467 \begin{cfa}[ showspaces=true,aboveskip=0pt]2468 1®, ®2®, ®3 4®, ®5®, ®62467 \begin{cfa}[mathescape=off,showspaces=true,belowskip=0pt] 2468 1®, ®2®, ®3 3®, ®4®, ®5 2469 2469 \end{cfa} 2470 2470 Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment. … … 2485 2485 \\ 2486 2486 & 2487 \begin{cfa}[ showspaces=true,aboveskip=0pt]2487 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2488 2488 3 3 12 0 3 1 2 2489 2489 \end{cfa} … … 2503 2503 sout | 1 | 2 | 3 | endl; 2504 2504 \end{cfa} 2505 \begin{cfa}[ showspaces=true,aboveskip=0pt,belowskip=0pt]2505 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2506 2506 1 2 3 2507 2507 \end{cfa} … … 2570 2570 \subsection{Manipulator} 2571 2571 2572 The following \CC-style \Index{manipulator}s and routines control implicit seperation.2572 The following routines and \CC-style \Index{manipulator}s control implicit seperation. 2573 2573 \begin{enumerate} 2574 2574 \item 2575 Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sep }\index{manipulator!sep@©sep©}/\Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.2575 Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string. 2576 2576 The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters). 2577 \begin{cfa}[mathescape=off, belowskip=0pt]2577 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2578 2578 sepSet( sout, ", $" ); §\C{// set separator from " " to ", \$"}§ 2579 sout | 1 | 2 | 3 | " \"" | ®sep ® | "\"" | endl;2579 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl; 2580 2580 \end{cfa} 2581 2581 %$ … … 2584 2584 \end{cfa} 2585 2585 %$ 2586 \begin{cfa}[ belowskip=0pt]2586 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2587 2587 sepSet( sout, " " ); §\C{// reset separator to " "}§ 2588 2588 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl; 2589 2589 \end{cfa} 2590 \begin{cfa}[ showspaces=true,aboveskip=0pt]2590 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2591 2591 1® ®2® ®3 ®" "® 2592 2592 \end{cfa} 2593 ©sepGet© can be used to store a separator and then restore it: 2594 \begin{cfa}[belowskip=0pt] 2595 char store[®sepSize®]; §\C{// sepSize is the maximum separator size}§ 2596 strcpy( store, sepGet( sout ) ); 2597 sepSet( sout, "_" ); 2598 sout | 1 | 2 | 3 | endl; 2599 \end{cfa} 2600 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2601 1®_®2®_®3 2602 \end{cfa} 2603 \begin{cfa}[belowskip=0pt] 2604 sepSet( sout, store ); 2605 sout | 1 | 2 | 3 | endl; 2606 \end{cfa} 2607 \begin{cfa}[showspaces=true,aboveskip=0pt] 2608 1® ®2® ®3 2609 \end{cfa} 2610 2611 \item 2612 Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepTuple}\index{manipulator!sepTuple@©sepTuple©}/\Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string. 2593 2594 \item 2595 Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string. 2613 2596 The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters). 2614 \begin{cfa}[ belowskip=0pt]2597 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2615 2598 sepSetTuple( sout, " " ); §\C{// set tuple separator from ", " to " "}§ 2616 sout | t1 | t2 | " \"" | ®sep Tuple® | "\"" | endl;2617 \end{cfa} 2618 \begin{cfa}[ showspaces=true,aboveskip=0pt]2619 1 2 3 4 5 6®" "®2620 \end{cfa} 2621 \begin{cfa}[ belowskip=0pt]2599 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl; 2600 \end{cfa} 2601 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2602 1 2 3 4 ®" "® 2603 \end{cfa} 2604 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2622 2605 sepSetTuple( sout, ", " ); §\C{// reset tuple separator to ", "}§ 2623 2606 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl; 2624 2607 \end{cfa} 2625 \begin{cfa}[showspaces=true,aboveskip=0pt] 2626 1, 2, 3 4, 5, 6 ®", "® 2627 \end{cfa} 2628 As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it. 2629 2630 \item 2631 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items. 2632 \begin{cfa}[belowskip=0pt] 2633 sout | sepDisable | 1 | 2 | 3 | endl; §\C{// globally turn off implicit separator}§ 2634 \end{cfa} 2635 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 2608 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt] 2609 1, 2, 3, 4 ®", "® 2610 \end{cfa} 2611 2612 \item 2613 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item. 2614 \begin{cfa}[mathescape=off,belowskip=0pt] 2615 sout | sepOn | 1 | 2 | 3 | sepOn | endl; §\C{// separator at start/end of line}§ 2616 \end{cfa} 2617 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2618 ® ®1 2 3® ® 2619 \end{cfa} 2620 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2621 sout | 1 | sepOff | 2 | 3 | endl; §\C{// locally turn off implicit separator}§ 2622 \end{cfa} 2623 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2624 12 3 2625 \end{cfa} 2626 The tuple separator also responses to being turned on and off. 2627 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2628 sout | sepOn | t1 | sepOff | t2 | endl; §\C{// locally turn on/off implicit separation}§ 2629 \end{cfa} 2630 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2631 , 1, 23, 4 2632 \end{cfa} 2633 Notice a tuple seperator starts the line because the next item is a tuple. 2634 2635 \item 2636 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items, unless locally adjusted. 2637 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2638 sout | sepDisable | 1 | 2 | 3 | endl; §\C{// globally turn off implicit separation}§ 2639 \end{cfa} 2640 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2636 2641 123 2637 2642 \end{cfa} 2638 \begin{cfa}[belowskip=0pt] 2639 sout | sepEnable | 1 | 2 | 3 | endl; §\C{// globally turn on implicit separator}§ 2643 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2644 sout | 1 | ®sepOn® | 2 | 3 | endl; §\C{// locally turn on implicit separator}§ 2645 \end{cfa} 2646 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2647 1® ®23 2648 \end{cfa} 2649 \begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt] 2650 sout | sepEnable | 1 | 2 | 3 | endl; §\C{// globally turn on implicit separation}§ 2640 2651 \end{cfa} 2641 2652 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] 2642 2653 1 2 3 2643 2654 \end{cfa} 2644 2645 \item2646 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item.2647 \begin{cfa}[belowskip=0pt]2648 sout | 1 | sepOff | 2 | 3 | endl; §\C{// locally turn off implicit separator}§2649 \end{cfa}2650 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]2651 12 32652 \end{cfa}2653 \begin{cfa}[belowskip=0pt]2654 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§2655 \end{cfa}2656 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]2657 1 232658 \end{cfa}2659 The tuple separator also responses to being turned on and off.2660 \begin{cfa}[belowskip=0pt]2661 sout | t1 | sepOff | t2 | endl; §\C{// locally turn on/off implicit separator}§2662 \end{cfa}2663 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]2664 1, 2, 34, 5, 62665 \end{cfa}2666 ©sepOn© \emph{cannot} be used to start/end a line with a separator because separators do not appear at the start/end of a line;2667 use ©sep© to accomplish this functionality.2668 \begin{cfa}[belowskip=0pt]2669 sout | sepOn | 1 | 2 | 3 | sepOn | endl ; §\C{// sepOn does nothing at start/end of line}§2670 \end{cfa}2671 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]2672 1 2 32673 \end{cfa}2674 \begin{cfa}[belowskip=0pt]2675 sout | sep | 1 | 2 | 3 | sep | endl ; §\C{// use sep to print separator at start/end of line}§2676 \end{cfa}2677 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]2678 ® ®1 2 3® ®2679 \end{cfa}2680 2655 \end{enumerate} 2681 2656 2682 2657 \begin{comment} 2683 2658 #include <fstream> 2684 #include <string.h> // strcpy2685 2659 2686 2660 int main( void ) { 2687 2661 int x = 1, y = 2, z = 3; 2688 2662 sout | x | y | z | endl; 2689 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6] ];2663 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ]; 2690 2664 sout | t1 | t2 | endl; // print tuples 2691 2665 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl; … … 2701 2675 2702 2676 sepSet( sout, ", $" ); // set separator from " " to ", $" 2703 sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;2677 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 2704 2678 sepSet( sout, " " ); // reset separator to " " 2705 2679 sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl; 2706 2680 2707 char store[sepSize];2708 s trcpy( store, sepGet( sout ) );2709 sepSet( sout, "_" ); 2710 sout | 1 | 2 | 3 | endl;2711 s epSet( sout, store );2712 sout | 1 | 2 | 3 | endl;2681 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start of line 2682 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator 2683 2684 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation 2685 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator 2686 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separation 2713 2687 2714 2688 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 2715 sout | t1 | t2 | " \"" | sep Tuple| "\"" | endl;2689 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 2716 2690 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 2717 2691 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 2718 2692 2719 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separator 2720 sout | sepEnable | 1 | 2 | 3 | endl; // globally turn on implicit separator 2721 2722 sout | 1 | sepOff | 2 | 3 | endl; // locally turn on implicit separator 2723 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator 2724 sout | sepEnable; 2725 sout | t1 | sepOff | t2 | endl; // locally turn on/off implicit separator 2726 2727 sout | sepOn | 1 | 2 | 3 | sepOn | endl ; // sepOn does nothing at start/end of line 2728 sout | sep | 1 | 2 | 3 | sep | endl ; // use sep to print separator at start/end of line 2693 sout | t1 | t2 | endl; // print tuple 2694 sout | sepOn | t1 | sepOff | t2 | endl; // locally turn on/off implicit separation 2729 2695 } 2730 2696 … … 5582 5548 // C unsafe allocation 5583 5549 extern "C" { 5584 void * mall oc( size_t size );§\indexc{memset}§5550 void * mallac( size_t size );§\indexc{memset}§ 5585 5551 void * calloc( size_t dim, size_t size );§\indexc{calloc}§ 5586 5552 void * realloc( void * ptr, size_t size );§\indexc{realloc}§ -
src/libcfa/fstream
r29038ef re182ce3 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 08:32:38201713 // Update Count : 11 712 // Last Modified On : Sat Jul 1 16:37:53 2017 13 // Update Count : 112 14 14 // 15 15 16 #pragma once 16 #ifndef __FSTREAM_H__ 17 #define __FSTREAM_H__ 17 18 18 19 #include "iostream" 19 20 20 enum { sep Size = 16 };21 enum { separateSize = 16 }; 21 22 struct ofstream { 22 23 void * file; 23 24 _Bool sepDefault; 24 25 _Bool sepOnOff; 25 _Bool sawNL;26 _Bool lastSepOn; 26 27 const char * sepCur; 27 char separator[sep Size];28 char tupleSeparator[sep Size];28 char separator[separateSize]; 29 char tupleSeparator[separateSize]; 29 30 }; // ofstream 30 31 … … 35 36 const char * sepGetCur( ofstream * ); 36 37 void sepSetCur( ofstream *, const char * ); 37 _Bool getNL( ofstream * ); 38 void setNL( ofstream *, _Bool ); 38 _Bool lastSepOn( ofstream * ); 39 39 40 40 // public … … 75 75 extern ifstream * sin; 76 76 77 #endif // __FSTREAM_H__ 78 77 79 // Local Variables: // 78 80 // mode: c // -
src/libcfa/fstream.c
r29038ef re182ce3 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 6 18:38:25201713 // Update Count : 2 5112 // Last Modified On : Sat Jul 1 16:37:54 2017 13 // Update Count : 242 14 14 // 15 15 … … 33 33 this->sepDefault = sepDefault; 34 34 this->sepOnOff = sepOnOff; 35 this->lastSepOn = false; 35 36 sepSet( this, separator ); 36 37 sepSetCur( this, sepGet( this ) ); … … 39 40 40 41 // private 41 _Bool sepPrt( ofstream * os ) { setNL( os, false ); return os->sepOnOff; } 42 _Bool lastSepOn( ofstream * os ) { return os->lastSepOn; } 43 _Bool sepPrt( ofstream * os ) { os->lastSepOn = false; return os->sepOnOff; } 42 44 void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; } 43 45 void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; } 44 46 const char * sepGetCur( ofstream * os ) { return os->sepCur; } 45 47 void sepSetCur( ofstream * os, const char * sepCur ) { os->sepCur = sepCur; } 46 _Bool getNL( ofstream * os ) { return os->sawNL; }47 void setNL( ofstream * os, _Bool state ) { os->sawNL = state; }48 48 49 49 // public 50 void sepOn( ofstream * os ) { os-> sepOnOff = ! getNL( os ); }51 void sepOff( ofstream * os ) { os-> sepOnOff = false; }50 void sepOn( ofstream * os ) { os->lastSepOn = true; os->sepOnOff = true; } 51 void sepOff( ofstream * os ) { os->lastSepOn = false; os->sepOnOff = 0; } 52 52 53 53 _Bool sepDisable( ofstream *os ) { 54 54 _Bool temp = os->sepDefault; 55 55 os->sepDefault = false; 56 os->lastSepOn = false; 56 57 sepReset( os ); 57 58 return temp; … … 68 69 void sepSet( ofstream * os, const char * s ) { 69 70 assert( s ); 70 strncpy( os->separator, s, sep Size - 1 );71 os->separator[sep Size - 1] = '\0';71 strncpy( os->separator, s, separateSize - 1 ); 72 os->separator[separateSize - 1] = '\0'; 72 73 } // sepSet 73 74 … … 75 76 void sepSetTuple( ofstream * os, const char * s ) { 76 77 assert( s ); 77 strncpy( os->tupleSeparator, s, sep Size - 1 );78 os->tupleSeparator[sep Size - 1] = '\0';78 strncpy( os->tupleSeparator, s, separateSize - 1 ); 79 os->tupleSeparator[separateSize - 1] = '\0'; 79 80 } // sepSet 80 81 … … 152 153 153 154 void open( ifstream * is, const char * name, const char * mode ) { 154 FILE * file= fopen( name, mode );155 if ( file == 0 ) {// do not change unless successful155 FILE *t = fopen( name, mode ); 156 if ( t == 0 ) { // do not change unless successful 156 157 fprintf( stderr, IO_MSG "open input file \"%s\", ", name ); 157 158 perror( 0 ); 158 159 exit( EXIT_FAILURE ); 159 160 } // if 160 is->file = file;161 is->file = t; 161 162 } // open 162 163 -
src/libcfa/gmp
r29038ef re182ce3 10 10 // Created On : Tue Apr 19 08:43:43 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 09:33:20201713 // Update Count : 1 512 // Last Modified On : Sat May 27 09:55:51 2017 13 // Update Count : 14 14 14 // 15 15 16 16 // https://gmplib.org/gmp-man-6.1.1.pdf 17 18 #pragma once19 17 20 18 #include <gmp.h> // GNU multi-precise integers -
src/libcfa/iostream
r29038ef re182ce3 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 08:35:59201713 // Update Count : 11 812 // Last Modified On : Sun Jul 2 08:42:56 2017 13 // Update Count : 110 14 14 // 15 15 16 #pragma once 16 #ifndef __IOSTREAM_H__ 17 #define __IOSTREAM_H__ 17 18 18 19 #include "iterator" … … 25 26 const char * sepGetCur( ostype * ); // get current separator string 26 27 void sepSetCur( ostype *, const char * ); // set current separator string 27 _Bool getNL( ostype * ); // check newline 28 void setNL( ostype *, _Bool ); // saw newline 28 _Bool lastSepOn( ostype * ); // last manipulator is setOn (context sensitive) 29 29 // public 30 30 void sepOn( ostype * ); // turn separator state on … … 82 82 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, ostype * (*)( ostype * ) ); 83 83 forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * ); 84 forall( dtype ostype | ostream( ostype ) ) ostype * sep( ostype * );85 forall( dtype ostype | ostream( ostype ) ) ostype * sepTuple( ostype * );86 84 forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * ); 87 85 forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * ); … … 139 137 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC ); 140 138 139 #endif // __IOSTREAM_H 140 141 141 // Local Variables: // 142 142 // mode: c // -
src/libcfa/iostream.c
r29038ef re182ce3 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 6 18:14:17201713 // Update Count : 3 9612 // Last Modified On : Sun Jul 2 08:54:02 2017 13 // Update Count : 375 14 14 // 15 15 … … 18 18 extern "C" { 19 19 #include <stdio.h> 20 #include <stdbool.h> // true/false21 20 #include <string.h> // strlen 22 21 #include <float.h> // DBL_DIG, LDBL_DIG … … 25 24 26 25 forall( dtype ostype | ostream( ostype ) ) 27 ostype * ?|?( ostype * os, char ch ) { 28 fmt( os, "%c", ch ); 29 if ( ch == '\n' ) setNL( os, true ); 26 ostype * ?|?( ostype * os, char c ) { 27 fmt( os, "%c", c ); 30 28 sepOff( os ); 31 29 return os; … … 182 180 183 181 // last character IS spacing or opening punctuation => turn off separator for next item 184 size_t len = strlen( cp );185 ch = cp[ len - 1];// must make unsigned182 unsigned int len = strlen( cp ), posn = len - 1; 183 ch = cp[posn]; // must make unsigned 186 184 if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) { 187 185 sepOn( os ); … … 189 187 sepOff( os ); 190 188 } // if 191 if ( ch == '\n' ) setNL( os, true ); // check *AFTER* sepPrt call above as it resets NL flag192 189 return write( os, cp, len ); 193 190 } // ?|? … … 219 216 220 217 forall( dtype ostype | ostream( ostype ) ) 221 ostype * sep( ostype * os ) {222 os | sepGet( os );223 return os;224 } // sep225 226 forall( dtype ostype | ostream( ostype ) )227 ostype * sepTuple( ostype * os ) {228 os | sepGetTuple( os );229 return os;230 } // sepTuple231 232 forall( dtype ostype | ostream( ostype ) )233 218 ostype * endl( ostype * os ) { 219 if ( lastSepOn( os ) ) fmt( os, "%s", sepGetCur( os ) ); 234 220 os | '\n'; 235 setNL( os, true );236 221 flush( os ); 237 222 sepOff( os ); // prepare for next line -
src/libcfa/iterator
r29038ef re182ce3 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 08:37:25 201713 // Update Count : 1012 // Last Modified On : Wed Mar 2 18:06:05 2016 13 // Update Count : 9 14 14 // 15 15 16 #pragma once 16 #ifndef ITERATOR_H 17 #define ITERATOR_H 17 18 18 19 // An iterator can be used to traverse a data structure. … … 38 39 39 40 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 40 void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) );41 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 41 42 42 43 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 43 void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ); 44 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 45 46 #endif // ITERATOR_H 44 47 45 48 // Local Variables: // -
src/libcfa/iterator.c
r29038ef re182ce3 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 08:38:23 201713 // Update Count : 2 812 // Last Modified On : Wed Mar 2 18:08:11 2016 13 // Update Count : 27 14 14 // 15 15 … … 17 17 18 18 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 19 void for_each( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) {19 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 20 20 for ( iterator_type i = begin; i != end; ++i ) { 21 21 func( *i ); 22 } // for23 } // for_each22 } 23 } 24 24 25 25 forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) 26 void for_each_reverse( iterator_type begin, iterator_type end, void (* func)( elt_type ) ) {26 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 27 27 for ( iterator_type i = end; i != begin; ) { 28 28 --i; 29 29 func( *i ); 30 } // for31 } // for_each_reverse30 } 31 } 32 32 33 33 // Local Variables: // -
src/libcfa/limits
r29038ef re182ce3 10 10 // Created On : Wed Apr 6 18:06:52 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 09:33:57 201713 // Update Count : 712 // Last Modified On : Wed Apr 6 21:08:16 2016 13 // Update Count : 6 14 14 // 15 15 16 #pragma once 16 #ifndef LIMITS_H 17 #define LIMITS_H 17 18 18 19 // Integral Constants … … 109 110 extern const long _Complex _1_SQRT_2; // 1 / sqrt(2) 110 111 112 #endif // LIMITS_H 113 111 114 // Local Variables: // 112 115 // mode: c // -
src/libcfa/math
r29038ef re182ce3 10 10 // Created On : Mon Apr 18 23:37:04 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 09:34:15 2017 13 // Update Count : 61 14 // 15 16 #pragma once 12 // Last Modified On : Wed May 24 17:40:39 2017 13 // Update Count : 60 14 // 15 16 #ifndef MATH_H 17 #define MATH_H 17 18 18 19 extern "C" { … … 344 345 long double scalbln( long double, long int ); 345 346 347 #endif // MATH_H 348 346 349 // Local Variables: // 347 350 // mode: c // -
src/libcfa/rational
r29038ef re182ce3 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Fri Jul 7 09:34:33201715 // Update Count : 9 314 // Last Modified On : Mon May 15 21:30:12 2017 15 // Update Count : 90 16 16 // 17 17 18 #pragma once 18 #ifndef RATIONAL_H 19 #define RATIONAL_H 19 20 20 21 #include "iostream" … … 46 47 // implementation 47 48 48 forall ( otype RationalImpl | arithmetic( RationalImpl ) )49 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 49 50 struct Rational { 50 51 RationalImpl numerator, denominator; // invariant: denominator > 0 … … 53 54 // constructors 54 55 55 forall ( otype RationalImpl | arithmetic( RationalImpl ) )56 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 56 57 void ?{}( Rational(RationalImpl) * r ); 57 58 58 forall ( otype RationalImpl | arithmetic( RationalImpl ) )59 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 59 60 void ?{}( Rational(RationalImpl) * r, RationalImpl n ); 60 61 61 forall ( otype RationalImpl | arithmetic( RationalImpl ) )62 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 62 63 void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d ); 63 64 64 forall ( otype RationalImpl | arithmetic( RationalImpl ) )65 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 65 66 void ?{}( Rational(RationalImpl) * r, zero_t ); 66 67 67 forall ( otype RationalImpl | arithmetic( RationalImpl ) )68 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 68 69 void ?{}( Rational(RationalImpl) * r, one_t ); 69 70 70 // numerator/denominator getter71 // getter for numerator/denominator 71 72 72 forall ( otype RationalImpl | arithmetic( RationalImpl ) )73 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 73 74 RationalImpl numerator( Rational(RationalImpl) r ); 74 75 75 forall ( otype RationalImpl | arithmetic( RationalImpl ) )76 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 76 77 RationalImpl denominator( Rational(RationalImpl) r ); 77 78 forall( otype RationalImpl | arithmetic( RationalImpl ) ) 78 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 79 79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ); 80 80 81 // numerator/denominator setter81 // setter for numerator/denominator 82 82 83 forall ( otype RationalImpl | arithmetic( RationalImpl ) )83 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 84 84 RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ); 85 85 86 forall ( otype RationalImpl | arithmetic( RationalImpl ) )86 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 87 87 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ); 88 88 89 89 // comparison 90 90 91 forall ( otype RationalImpl | arithmetic( RationalImpl ) )91 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 92 92 int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 93 93 94 forall ( otype RationalImpl | arithmetic( RationalImpl ) )94 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 95 95 int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 96 96 97 forall ( otype RationalImpl | arithmetic( RationalImpl ) )97 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 98 98 int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 99 99 100 forall ( otype RationalImpl | arithmetic( RationalImpl ) )100 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 101 101 int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 102 102 103 forall ( otype RationalImpl | arithmetic( RationalImpl ) )103 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 104 104 int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 105 105 106 forall ( otype RationalImpl | arithmetic( RationalImpl ) )106 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 107 107 int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 108 108 109 109 // arithmetic 110 110 111 forall ( otype RationalImpl | arithmetic( RationalImpl ) )111 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 112 112 Rational(RationalImpl) +?( Rational(RationalImpl) r ); 113 113 114 forall ( otype RationalImpl | arithmetic( RationalImpl ) )114 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 115 115 Rational(RationalImpl) -?( Rational(RationalImpl) r ); 116 116 117 forall ( otype RationalImpl | arithmetic( RationalImpl ) )117 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 118 118 Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 119 119 120 forall ( otype RationalImpl | arithmetic( RationalImpl ) )120 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 121 121 Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 122 122 123 forall ( otype RationalImpl | arithmetic( RationalImpl ) )123 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 124 124 Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 125 125 126 forall ( otype RationalImpl | arithmetic( RationalImpl ) )126 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 127 127 Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ); 128 128 129 129 // conversion 130 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )130 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } ) 131 131 double widen( Rational(RationalImpl) r ); 132 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double );} )132 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double );} ) 133 133 Rational(RationalImpl) narrow( double f, RationalImpl md ); 134 134 135 135 // I/O 136 forall ( otype RationalImpl | arithmetic( RationalImpl ) )136 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 137 137 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } ) 138 138 istype * ?|?( istype *, Rational(RationalImpl) * ); 139 139 140 forall ( otype RationalImpl | arithmetic( RationalImpl ) )140 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 141 141 forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } ) 142 142 ostype * ?|?( ostype *, Rational(RationalImpl ) ); 143 144 #endif // RATIONAL_H 143 145 144 146 // Local Variables: // -
src/libcfa/rational.c
r29038ef re182ce3 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 16 18:35:36201713 // Update Count : 1 5012 // Last Modified On : Mon May 15 21:29:23 2017 13 // Update Count : 149 14 14 // 15 15 … … 22 22 // Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals. 23 23 // alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm 24 forall ( otype RationalImpl | arithmetic( RationalImpl ) )24 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 25 25 static RationalImpl gcd( RationalImpl a, RationalImpl b ) { 26 26 for ( ;; ) { // Euclid's algorithm … … 33 33 } // gcd 34 34 35 forall ( otype RationalImpl | arithmetic( RationalImpl ) )35 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 36 36 static RationalImpl simplify( RationalImpl * n, RationalImpl * d ) { 37 37 if ( *d == (RationalImpl){0} ) { … … 46 46 // constructors 47 47 48 forall ( otype RationalImpl | arithmetic( RationalImpl ) )48 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 49 49 void ?{}( Rational(RationalImpl) * r ) { 50 50 r{ (RationalImpl){0}, (RationalImpl){1} }; 51 51 } // rational 52 52 53 forall ( otype RationalImpl | arithmetic( RationalImpl ) )53 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 54 54 void ?{}( Rational(RationalImpl) * r, RationalImpl n ) { 55 55 r{ n, (RationalImpl){1} }; 56 56 } // rational 57 57 58 forall ( otype RationalImpl | arithmetic( RationalImpl ) )58 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 59 59 void ?{}( Rational(RationalImpl) * r, RationalImpl n, RationalImpl d ) { 60 60 RationalImpl t = simplify( &n, &d ); // simplify … … 66 66 // getter for numerator/denominator 67 67 68 forall ( otype RationalImpl | arithmetic( RationalImpl ) )68 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 69 69 RationalImpl numerator( Rational(RationalImpl) r ) { 70 70 return r.numerator; 71 71 } // numerator 72 72 73 forall ( otype RationalImpl | arithmetic( RationalImpl ) )73 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 74 74 RationalImpl denominator( Rational(RationalImpl) r ) { 75 75 return r.denominator; 76 76 } // denominator 77 77 78 forall ( otype RationalImpl | arithmetic( RationalImpl ) )78 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 79 79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) { 80 80 return *dest = src.[ numerator, denominator ]; … … 83 83 // setter for numerator/denominator 84 84 85 forall ( otype RationalImpl | arithmetic( RationalImpl ) )85 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 86 86 RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) { 87 87 RationalImpl prev = r.numerator; … … 92 92 } // numerator 93 93 94 forall ( otype RationalImpl | arithmetic( RationalImpl ) )94 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 95 95 RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) { 96 96 RationalImpl prev = r.denominator; … … 104 104 // comparison 105 105 106 forall ( otype RationalImpl | arithmetic( RationalImpl ) )106 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 107 107 int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 108 108 return l.numerator * r.denominator == l.denominator * r.numerator; 109 109 } // ?==? 110 110 111 forall ( otype RationalImpl | arithmetic( RationalImpl ) )111 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 112 112 int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 113 113 return ! ( l == r ); 114 114 } // ?!=? 115 115 116 forall ( otype RationalImpl | arithmetic( RationalImpl ) )116 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 117 117 int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 118 118 return l.numerator * r.denominator < l.denominator * r.numerator; 119 119 } // ?<? 120 120 121 forall ( otype RationalImpl | arithmetic( RationalImpl ) )121 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 122 122 int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 123 123 return l.numerator * r.denominator <= l.denominator * r.numerator; 124 124 } // ?<=? 125 125 126 forall ( otype RationalImpl | arithmetic( RationalImpl ) )126 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 127 127 int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 128 128 return ! ( l <= r ); 129 129 } // ?>? 130 130 131 forall ( otype RationalImpl | arithmetic( RationalImpl ) )131 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 132 132 int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 133 133 return ! ( l < r ); … … 137 137 // arithmetic 138 138 139 forall ( otype RationalImpl | arithmetic( RationalImpl ) )139 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 140 140 Rational(RationalImpl) +?( Rational(RationalImpl) r ) { 141 141 Rational(RationalImpl) t = { r.numerator, r.denominator }; … … 143 143 } // +? 144 144 145 forall ( otype RationalImpl | arithmetic( RationalImpl ) )145 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 146 146 Rational(RationalImpl) -?( Rational(RationalImpl) r ) { 147 147 Rational(RationalImpl) t = { -r.numerator, r.denominator }; … … 149 149 } // -? 150 150 151 forall ( otype RationalImpl | arithmetic( RationalImpl ) )151 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 152 152 Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 153 153 if ( l.denominator == r.denominator ) { // special case … … 160 160 } // ?+? 161 161 162 forall ( otype RationalImpl | arithmetic( RationalImpl ) )162 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 163 163 Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 164 164 if ( l.denominator == r.denominator ) { // special case … … 171 171 } // ?-? 172 172 173 forall ( otype RationalImpl | arithmetic( RationalImpl ) )173 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 174 174 Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 175 175 Rational(RationalImpl) t = { l.numerator * r.numerator, l.denominator * r.denominator }; … … 177 177 } // ?*? 178 178 179 forall ( otype RationalImpl | arithmetic( RationalImpl ) )179 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 180 180 Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) { 181 181 if ( r.numerator < (RationalImpl){0} ) { … … 190 190 // conversion 191 191 192 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )192 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } ) 193 193 double widen( Rational(RationalImpl) r ) { 194 194 return convert( r.numerator ) / convert( r.denominator ); … … 196 196 197 197 // http://www.ics.uci.edu/~eppstein/numth/frap.c 198 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )198 forall ( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } ) 199 199 Rational(RationalImpl) narrow( double f, RationalImpl md ) { 200 200 if ( md <= (RationalImpl){1} ) { // maximum fractional digits too small? … … 227 227 // I/O 228 228 229 forall ( otype RationalImpl | arithmetic( RationalImpl ) )229 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 230 230 forall( dtype istype | istream( istype ) | { istype * ?|?( istype *, RationalImpl * ); } ) 231 231 istype * ?|?( istype * is, Rational(RationalImpl) * r ) { … … 238 238 } // ?|? 239 239 240 forall ( otype RationalImpl | arithmetic( RationalImpl ) )240 forall ( otype RationalImpl | arithmetic( RationalImpl ) ) 241 241 forall( dtype ostype | ostream( ostype ) | { ostype * ?|?( ostype *, RationalImpl ); } ) 242 242 ostype * ?|?( ostype * os, Rational(RationalImpl ) r ) { -
src/libcfa/stdlib
r29038ef re182ce3 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 09:34:49 2017 13 // Update Count : 219 14 // 15 16 #pragma once 12 // Last Modified On : Fri Jun 2 15:51:03 2017 13 // Update Count : 218 14 // 15 16 #ifndef STDLIB_H 17 #define STDLIB_H 17 18 18 19 //--------------------------------------- … … 231 232 void swap( T * t1, T * t2 ); 232 233 234 #endif // STDLIB_H 235 233 236 // Local Variables: // 234 237 // mode: c // -
src/tests/.expect/io.txt
r29038ef re182ce3 4 4 123 5 5 6 opening delimiters 6 opening delimiters 7 7 x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10 8 8 9 closing delimiters 10 1, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x 9 closing delimiters 10 1, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x 11 11 12 opening/closing delimiters 12 opening/closing delimiters 13 13 x`1`x'2'x"3"x:4:x 5 x 6 x 14 14 7 … … 19 19 x 20 20 10 21 x 21 x 22 22 23 override opening/closing delimiters 23 override opening/closing delimiters 24 24 x ( 1 ) x 2 , x 3 :x: 4 25 25 26 input bacis types 26 input bacis types 27 27 28 output basic types 28 output basic types 29 29 A 30 30 1 2 3 4 5 6 7 8 … … 32 32 1.1+2.3i 1.1-2.3i 1.1-2.3i 33 33 34 tuples 35 1, 2, 3 4, 5, 634 tuples 35 1, 2, 3 3, 4, 5 36 36 37 toggle separator 37 toggle separator 38 38 1.11.21.3 39 39 1.1+2.3i1.1-2.3i1.1-2.3i 40 1.1+2.3i 1.1-2.3i1.1-2.3i 41 1.1+2.3i 1.1-2.3i 1.1-2.3i 42 1.1+2.3i1.1-2.3i 1.1-2.3i 43 abcxyz 44 abcxyz 40 abcxyz 41 abcxyz 45 42 46 change separator 47 from " " to ", $"43 change separator 44 from " "to " , $" 48 45 1.1, $1.2, $1.3 49 46 1.1+2.3i, $1.1-2.3i, $1.1-2.3i 50 abc, $xyz 51 1, 2, 3, $ 4, 5, 647 abc, $xyz, $ 48 1, 2, 3, $3, 4, 5 52 49 53 from ", $" to " "50 from ", $"to " " 54 51 1.1 1.2 1.3 55 52 1.1+2.3i 1.1-2.3i 1.1-2.3i 56 abc xyz 57 1, 2, 3 4, 5, 653 abc xyz 54 1, 2, 3 3, 4, 5 58 55 59 check sepOn/sepOff 56 1 2 3 57 12 3 58 1 2 3 60 59 1 2 3 61 12 3 62 1 2 3 63 1 2 3 60 1 2 3 64 61 65 1 2 366 67 check enable/disable68 62 123 69 63 1 23 … … 71 65 123 72 66 1 2 3 73 123 67 123 74 68 1 2 3 75 69 76 1 2 3 4 5 6" "77 1, 2, 3 4, 5, 6 ""78 1, 2, 3 4, 5, 670 1 2 3 3 4 5 " " 71 1, 2, 3 3, 4, 5 ", " 72 1, 2, 3 3, 4, 5 79 73 80 74 3, 4, a, 7.2 81 75 3, 4, a, 7.2 82 76 3 4 a 7.2 83 3 4 a 7.234a7.23 4 a 7.277 3 4 a 7.234a7.23 4 a 7.2 84 78 3-4-a-7.2^3^4^3-4-a-7.2 -
src/tests/io.c
r29038ef re182ce3 10 10 // Created On : Wed Mar 2 16:56:02 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 6 23:26:12201713 // Update Count : 7812 // Last Modified On : Sun Jul 2 09:40:58 2017 13 // Update Count : 68 14 14 // 15 15 … … 104 104 105 105 sout | "tuples" | endl; 106 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6] ];106 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ]; 107 107 sout | t1 | t2 | endl; // print tuple 108 108 sout | endl; … … 110 110 sout | "toggle separator" | endl; 111 111 sout | f | "" | d | "" | ld | endl // floating point without separator 112 | sepDisable | fc | dc | ldc | endl // complex without separator 113 | fc | sepOn | dc | ldc | endl // local separator add 114 | sepEnable | fc | dc | ldc | endl // complex with separator 115 | fc | sepOff | dc | ldc | endl // local separator removal 116 | s1 | sepOff | s2 | endl // local separator removal 117 | s1 | "" | s2 | endl; // local separator removal 112 | sepDisable | fc | dc | ldc | sepEnable | endl // complex without separator 113 | sepOn | s1 | sepOff | s2 | endl // local separator removal 114 | s1 | "" | s2 | endl; // C string without separator 118 115 sout | endl; 119 116 120 117 sout | "change separator" | endl; 121 sout | "from \" " | sep| "\"";118 sout | "from \" " | sepGet( sout ) | "\""; 122 119 sepSet( sout, ", $" ); // change separator, maximum of 15 characters 123 sout | " to \"" | sep| "\"" | endl;120 sout | "to \" " | sepGet( sout ) | "\"" | endl; 124 121 sout | f | d | ld | endl 125 122 | fc | dc | ldc | endl … … 127 124 | t1 | t2 | endl; // print tuple 128 125 sout | endl; 129 sout | "from \"" | sep | "\"";126 sout | "from \"" | sepGet( sout ) | "\""; 130 127 sepSet( sout, " " ); // restore separator 131 sout | "to \"" | sep | "\"" | endl;128 sout | "to \"" | sepGet( sout ) | "\"" | endl; 132 129 sout | f | d | ld | endl 133 130 | fc | dc | ldc | endl … … 136 133 sout | endl; 137 134 138 sout | "check sepOn/sepOff" | endl; 139 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // no separator at start/end of line 135 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // separator at start/end of line 140 136 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator 141 sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/endof line142 sout | 1 | 2 | 3 | "\n\n" | sepOn; // noseparator at start of next line137 sout | sepOn | 1 | 2 | 3 | sepOn | sepOff | endl; // separator at start of line 138 sout | 1 | 2 | 3 | endl | sepOn; // separator at start of next line 143 139 sout | 1 | 2 | 3 | endl; 144 140 sout | endl; 145 141 146 sout | "check enable/disable" | endl;147 142 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation 148 143 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator … … 154 149 sout | endl; 155 150 156 // sout | fmt( d, "%8.3f" ) || endl;157 // sout | endl;158 159 151 sepSetTuple( sout, " " ); // set tuple separator from ", " to " " 160 sout | t1 | t2 | " \"" | sep | "\"" | endl;152 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 161 153 sepSetTuple( sout, ", " ); // reset tuple separator to ", " 162 sout | t1 | t2 | " \"" | sep | "\"" | endl;154 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl; 163 155 sout | t1 | t2 | endl; // print tuple 164 156 sout | endl;
Note:
See TracChangeset
for help on using the changeset viewer.