Rev 5283 | Rev 5360 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5283 | Rev 5356 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | 3,1,2,10,5,1 |
19 | 3,1,2,10,5,1 |
20 | 3,1,2,10,5,1 |
20 | 3,1,2,10,5,1 |
21 | 5,1,4,10,5,1 |
21 | 5,1,4,10,5,1 |
22 | 3,2,2,10,5,0 |
22 | 3,2,2,10,5,0 |
23 | -1,-1,-1,-1,-1,-1 |
23 | -1,-1,-1,-1,-1,-1 |
24 | - | ||
25 | 24 | ||
26 | result is |
25 | result is |
27 | 1 line per input number |
26 | 1 line per input number |
28 | 6 items per line: |
27 | 6 items per line: |
29 | 28 | ||
Line 46... | Line 45... | ||
46 | - if number is 'nonsense' : -1,-1,-1,-1,-1 (1.23.4567 10^1.23.4 ; number will produce NaN in other math software) |
45 | - if number is 'nonsense' : -1,-1,-1,-1,-1 (1.23.4567 10^1.23.4 ; number will produce NaN in other math software) |
47 | 46 | ||
48 | ruleset: |
47 | ruleset: |
49 | 120.2 : 4 significant digits |
48 | 120.2 : 4 significant digits |
50 | 120.2000 : 7 significant digits |
49 | 120.2000 : 7 significant digits |
51 |
|
50 | 0.0000120 : 3 significant digits |
52 | scientiffic notation: |
51 | scientiffic notation: |
53 | 1.202*10^5 : 4 significant digits |
52 | 1.202*10^5 : 4 significant digits |
54 | 1.20200*10^5 : 6 significant digits |
53 | 1.20200*10^5 : 6 significant digits |
55 | 54 | ||
56 | 55 | ||
Line 96... | Line 95... | ||
96 | return 0; |
95 | return 0; |
97 | } |
96 | } |
98 | input++; |
97 | input++; |
99 | } |
98 | } |
100 | input = argv[cnt]; |
99 | input = argv[cnt]; |
- | 100 | // better way to use strncpy |
|
101 | strncpy( word, input, |
101 | strncpy( word, input, MAX_DIGITS - strlen(word)-1); |
102 | // reset |
102 | // reset |
103 | found_digit = 0; |
103 | found_digit = 0; |
104 | found_point = 0; |
104 | found_point = 0; |
105 | found_power = 0; |
105 | found_power = 0; |
106 | bracket = 0; |
106 | bracket = 0; |
Line 139... | Line 139... | ||
139 | break; |
139 | break; |
140 | case 'e' : if(found_point == 1){points--;found_point = 0;} found_power++;pow = length - i;sig1 = 0;sig2 = 0;dec1 = 0;found_digit = 0;zeros = 0;found_multiply++;break; |
140 | case 'e' : if(found_point == 1){points--;found_point = 0;} found_power++;pow = length - i;sig1 = 0;sig2 = 0;dec1 = 0;found_digit = 0;zeros = 0;found_multiply++;break; |
141 | case 'E' : if(found_point == 1){points--;found_point = 0;} found_power++;pow = length - i;sig1 = 0;sig2 = 0;dec1 = 0;found_digit = 0;zeros = 0;found_multiply++;break; |
141 | case 'E' : if(found_point == 1){points--;found_point = 0;} found_power++;pow = length - i;sig1 = 0;sig2 = 0;dec1 = 0;found_digit = 0;zeros = 0;found_multiply++;break; |
142 | case '0' : |
142 | case '0' : |
143 | if(i == 0){//last char |
143 | if(i == 0){//last char |
- | 144 | fprintf(stdout,"last zero : sig1 - zeros = %d - %d\n",sig1,zeros ); |
|
144 | sig1 = sig1 - zeros; |
145 | sig1 = sig1 - zeros; |
145 | sig2++; |
146 | sig2++; |
146 | if(found_power == 1){zeros++;} |
147 | if(found_power == 1){zeros++;} |
147 | } |
148 | } |
148 | else |
149 | else |
Line 184... | Line 185... | ||
184 | fprintf(stdout,"-1,-1,-1,-1,-1,-1\n"); |
185 | fprintf(stdout,"-1,-1,-1,-1,-1,-1\n"); |
185 | } |
186 | } |
186 | else |
187 | else |
187 | { |
188 | { |
188 | // extra check for handling "special cases" |
189 | // extra check for handling "special cases" |
- | 190 | if(found_point == 1 && found_power == 0 && found_multiply == 0 && word[1] == '.'){ok = 1;}// just a decimal number 0.1233 |
|
- | 191 | else |
|
189 | if(found_point == 0 && found_power == 0){ sig2 = length;ok = 1; } // just a number 12345 |
192 | if(found_point == 0 && found_power == 0){ sig2 = length;ok = 1; } // just a number 12345 |
190 | else |
193 | else |
191 | if(found_point == 0 && found_multiply == 0 && found_power == 1){ sig1 = 0; sig2 = 0 ; dec1 = 0; } // 10^5 |
194 | if(found_point == 0 && found_multiply == 0 && found_power == 1){ sig1 = 0; sig2 = 0 ; dec1 = 0; } // 10^5 |
192 | else |
195 | else |
193 | if(found_point == 1 && found_multiply == 0 && found_power == 1){ sig1 = 0; sig2 = 0 ; dec1 = 0; } // 10^5.1 |
196 | if(found_point == 1 && found_multiply == 0 && found_power == 1){ sig1 = 0; sig2 = 0 ; dec1 = 0; } // 10^5.1 |
194 | else |
197 | else |
195 | if(found_point == 0 && found_multiply == 1 && found_power == 1){ dec1 = 0; sig2 = length - zeros - pow;} // 3*10^5 |
198 | if(found_point == 0 && found_multiply == 1 && found_power == 1){ dec1 = 0; sig2 = length - zeros - pow;} // 3*10^5 |
196 | 199 | ||
197 | if( found_power == 1){ |
200 | if( found_power == 1){ |
198 | // find out if scientiffic number is correctly written ; ok=0 -> ok=1 |
201 | // find out if scientiffic number is correctly written ; ok=0 -> ok=1 |
199 | // rule [1-9].[0-9]* x10^exp |
202 | // rule [1-9].[0-9]* x10^exp |
200 | if( word[0] != '0' && word[1] == '.' ){ // 0.120*10^5 => 1.20*10^4 |
203 | if( word[0] != '0' && word[1] == '.' ){ // 0.120*10^5 => 1.20*10^4 |
201 | ok = 1; |
204 | ok = 1; |