@@ -31,22 +31,18 @@ namespace Pebbles {
3131
3232 public string get_result (string exp , GlobalAngleUnit angle_mode_in , int ? float_accuracy = -1 , bool ? tokenize = true ) {
3333 var result = exp;
34+ warning(result);
3435 if (tokenize) {
35- result = Utils . st_tokenize (exp);
36+ result = Utils . st_tokenize (exp. replace ( Utils . get_local_radix_symbol (), " . " ) );
3637 }
3738 angle_mode_sci = angle_mode_in;
3839 if (result == " E" ) {
39- return result ;
40+ return " E " ;
4041 }
41- string evaluated_result = evaluate_exp (result, float_accuracy);
42- if (evaluated_result == " nan" )
43- evaluated_result = " E" ;
44- if (evaluated_result == " inf" )
45- evaluated_result = " ∞" ;
46- return evaluated_result;
42+ return evaluate_exp (result, float_accuracy);
4743 }
4844
49- private static bool has_precedence (char op1 , char op2 ) {
45+ private static bool has_precedence_pemdas (char op1 , char op2 ) {
5046 if (op2 == ' (' || op2 == ' )' ) {
5147 return false ;
5248 }
@@ -69,10 +65,10 @@ namespace Pebbles {
6965 else if ((op1 == ' ^' || op1 == ' q' ) && (op2 == ' *' || op2 == ' /' || op2 == ' -' || op2 == ' +' || op2 == ' m' )) {
7066 return false ;
7167 }
72- else if ((op1 == ' * ' || op1 == ' m ' ) && ( op2 == ' / ' || op2 == ' +' || op2 == ' -' )) {
68+ else if ((op1 == ' m ' ) && (op2 == ' / ' || op2 == ' * ' || op2 == ' +' || op2 == ' -' )) {
7369 return false ;
7470 }
75- else if ((op1 == ' /' ) && (op2 == ' +' || op2 == ' -' )) {
71+ else if ((op1 == ' /' || op1 == ' * ' ) && (op2 == ' +' || op2 == ' -' )) {
7672 return false ;
7773 }
7874 else {
@@ -285,7 +281,7 @@ namespace Pebbles {
285281
286282 // If token is an operator
287283 else if (is_operator(tokens[i])) {
288- while (! r_l_associative (tokens[i]) && ! ops. empty() && has_precedence (tokens[i]. get (0 ), ops. peek())) {
284+ while (! r_l_associative (tokens[i]) && ! ops. empty() && has_precedence_pemdas (tokens[i]. get (0 ), ops. peek())) {
289285 string tmp = apply_op(ops. pop(), values. pop(), values. pop());
290286 if (tmp != " E" ) {
291287 values. push(double . parse(tmp));
@@ -311,35 +307,7 @@ namespace Pebbles {
311307
312308 // Take care of float accuracy of the result
313309 string output = Utils . manage_decimal_places (values. pop (), float_accuracy);
314-
315- // Remove trailing 0s and decimals
316- while (output. has_suffix (" 0" )) {
317- output = output. slice (0 , - 1 );
318- }
319- if (output. has_suffix (" ." )) {
320- output = output. slice (0 , - 1 );
321- }
322-
323- // Insert separator symbol in large numbers
324- StringBuilder output_builder = new StringBuilder (output);
325- var decimalPos = output. last_index_of (" ." );
326- if (decimalPos == - 1 ) {
327- decimalPos = output. length;
328- }
329- int end_position = 0 ;
330-
331- // Take care of minus sign at the beginning of string, if any
332- if (output. has_prefix (" -" )) {
333- end_position = 1 ;
334- }
335- for (int i = decimalPos - 3 ; i > end_position; i - = 3 ) {
336- output_builder. insert (i, " ," );
337- }
338-
339- if (output_builder. str == " -0" ) {
340- return " 0" ;
341- }
342- return output_builder. str;
310+ return output;
343311 }
344312 private static bool r_l_associative (string operator ) {
345313 if (operator == " u" || operator == " ^" || operator == " " ) {
0 commit comments