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