| 1 | //
 | 
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
| 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
| 6 | //
 | 
|---|
| 7 | // ato.cfa --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Peter A. Buhr
 | 
|---|
| 10 | // Created On       : Thu Feb  4 08:10:57 2016
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Tue Dec  4 21:33:53 2018
 | 
|---|
| 13 | // Update Count     : 92
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <fstream.hfa>
 | 
|---|
| 17 | #include <stdlib.hfa>                                                                           // ato, strto
 | 
|---|
| 18 | 
 | 
|---|
| 19 | int main( void ) {
 | 
|---|
| 20 |         const char * sptr = "-123";
 | 
|---|
| 21 |         int i = ato( sptr );
 | 
|---|
| 22 |         sout | i | sptr;
 | 
|---|
| 23 |         sptr = "123";
 | 
|---|
| 24 |         unsigned int ui = ato( sptr );
 | 
|---|
| 25 |         sout | ui | sptr;
 | 
|---|
| 26 | 
 | 
|---|
| 27 |         sptr = "-123";
 | 
|---|
| 28 |         long int li = ato( sptr );
 | 
|---|
| 29 |         sout | li | sptr;
 | 
|---|
| 30 |         sptr = "123";
 | 
|---|
| 31 |         unsigned long int uli = ato( sptr );
 | 
|---|
| 32 |         sout | uli | sptr;
 | 
|---|
| 33 | 
 | 
|---|
| 34 |         sptr = "-123";
 | 
|---|
| 35 |         long long int lli = ato( sptr );
 | 
|---|
| 36 |         sout | lli | sptr;
 | 
|---|
| 37 |         sptr = "123";
 | 
|---|
| 38 |         unsigned long long int ulli = ato( sptr );
 | 
|---|
| 39 |         sout | ulli | sptr;
 | 
|---|
| 40 | 
 | 
|---|
| 41 |         sptr = "-123.456";
 | 
|---|
| 42 |         float f = ato( sptr );
 | 
|---|
| 43 |         sout | f | sptr;
 | 
|---|
| 44 |         sptr = "-123.4567890123456";
 | 
|---|
| 45 |         double d = ato( sptr );
 | 
|---|
| 46 |         sout | d | sptr;
 | 
|---|
| 47 |         sptr = "-123.45678901234567890123456789";
 | 
|---|
| 48 |         long double ld = ato( sptr );
 | 
|---|
| 49 |         sout | ld | sptr;
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         sptr = "-123.456-123.456i";
 | 
|---|
| 52 |         float _Complex fc = ato( sptr );
 | 
|---|
| 53 |         sout | fc | sptr;
 | 
|---|
| 54 |         sptr = "-123.4567890123456+123.4567890123456i";
 | 
|---|
| 55 |         double _Complex dc = ato( sptr );
 | 
|---|
| 56 |         sout | dc | sptr;
 | 
|---|
| 57 |         sptr = "123.45678901234567890123456789-123.45678901234567890123456789i";
 | 
|---|
| 58 |         long double _Complex ldc = ato( sptr );
 | 
|---|
| 59 |         sout | ldc | sptr;
 | 
|---|
| 60 |         sptr = "123.45678901234-123.4567890i";
 | 
|---|
| 61 |         long double _Complex ldc2 = ato( sptr );
 | 
|---|
| 62 |         sout | ldc2 | sptr;
 | 
|---|
| 63 | 
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         sptr = "-123";
 | 
|---|
| 66 |         i = strto( sptr, 0, 10 );
 | 
|---|
| 67 |         sout | i | sptr;
 | 
|---|
| 68 |         sptr = "123";
 | 
|---|
| 69 |         ui = strto( sptr, 0, 10 );
 | 
|---|
| 70 |         sout | ui | sptr;
 | 
|---|
| 71 | 
 | 
|---|
| 72 |         sptr = "-123";
 | 
|---|
| 73 |         li = strto( sptr, 0, 10 );
 | 
|---|
| 74 |         sout | li | sptr;
 | 
|---|
| 75 |         sptr = "123";
 | 
|---|
| 76 |         uli = strto( sptr, 0, 10 );
 | 
|---|
| 77 |         sout | uli | sptr;
 | 
|---|
| 78 | 
 | 
|---|
| 79 |         sptr = "-123";
 | 
|---|
| 80 |         lli = strto( sptr, 0, 10 );
 | 
|---|
| 81 |         sout | lli | sptr;
 | 
|---|
| 82 |         sptr = "123";
 | 
|---|
| 83 |         ulli = strto( sptr, 0, 10 );
 | 
|---|
| 84 |         sout | ulli | sptr;
 | 
|---|
| 85 | 
 | 
|---|
| 86 |         sptr = "-123.456";
 | 
|---|
| 87 |         f = strto( sptr, 0 );
 | 
|---|
| 88 |         sout | f | sptr;
 | 
|---|
| 89 |         sptr = "-123.4567890123456";
 | 
|---|
| 90 |         d = strto( sptr, 0 );
 | 
|---|
| 91 |         sout | d | sptr;
 | 
|---|
| 92 |         sptr = "-123.45678901234567890123456789";
 | 
|---|
| 93 |         ld = strto( sptr, 0 );
 | 
|---|
| 94 |         sout | ld | sptr;
 | 
|---|
| 95 | 
 | 
|---|
| 96 |         sptr = "-123.456-123.456i";
 | 
|---|
| 97 |         fc = strto( sptr, 0 );
 | 
|---|
| 98 |         sout | fc | sptr;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |         char * eptr = 0;
 | 
|---|
| 101 |         // sptr = "2fred";
 | 
|---|
| 102 |         // fc = strto( sptr, &eptr );
 | 
|---|
| 103 |         // sout | fc | sptr | eptr;
 | 
|---|
| 104 | 
 | 
|---|
| 105 |         sptr = "2  3";
 | 
|---|
| 106 |         fc = strto( sptr, &eptr );
 | 
|---|
| 107 |         sout | fc | sptr | eptr;
 | 
|---|
| 108 | 
 | 
|---|
| 109 |         sptr = "-123.4567890123456+123.4567890123456i";
 | 
|---|
| 110 |         dc = strto( sptr, 0 );
 | 
|---|
| 111 |         sout | dc | sptr;
 | 
|---|
| 112 |         sptr = "123.45678901234567890123456789-123.45678901234567890123456789i";
 | 
|---|
| 113 |         ldc = strto( sptr, 0 );
 | 
|---|
| 114 |         sout | ldc | sptr;
 | 
|---|
| 115 |         sptr = "123.45678901234-123.4567890i";
 | 
|---|
| 116 |         ldc2 = strto( sptr, 0 );
 | 
|---|
| 117 |         sout | ldc2 | sptr;
 | 
|---|
| 118 | } // main
 | 
|---|
| 119 | 
 | 
|---|
| 120 | // Local Variables: //
 | 
|---|
| 121 | // tab-width: 4 //
 | 
|---|
| 122 | // compile-command: "cfa ato.cfa" //
 | 
|---|
| 123 | // End: //
 | 
|---|