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