fix precision
authorMazet Laurent <mazet@softndesign.org>
Sun, 1 Jan 2023 21:38:52 +0000 (22:38 +0100)
committerMazet Laurent <mazet@softndesign.org>
Sun, 1 Jan 2023 21:38:52 +0000 (22:38 +0100)
calc.c
getcomments.pl [changed mode: 0644->0755]
parser.c
parser.h

diff --git a/calc.c b/calc.c
index 41cc6e048a7e8129b7ea06c850403ba640f69ce2..e255bd2ca421baf948ee8400f8685859555d1960 100644 (file)
--- a/calc.c
+++ b/calc.c
@@ -163,8 +163,8 @@ int main (int argc, char *argv[])
 // test: echo "2 ^ 3 * 4 + 5" | calc.exe | grep -q '=> 3.7e1'
 // test: echo "2 + 3 * 4 ^ 5" | calc.exe | grep -q '=> 3.074e3'
 // test: echo "2 ^ 3 * 4 + cos(5/6)" | calc.exe | grep -q '=> 3.267241e1'
-// test: echo "95-6.3*15-1" | calc.exe | grep -q '=> -5.000028e-1'
-// test: echo "95 - 6.3 * 15 - 1" | calc.exe | grep -q '=> -5.000028e-1'
+// test: echo "95-6.3*15-1" | calc.exe | grep -q '=> -5e-1'
+// test: echo "95 - 6.3 * 15 - 1" | calc.exe | grep -q '=> -5e-1'
 // test: echo "95-6.3+15" | calc.exe | grep -q '=> 1.037e2'
 // test: echo "-cos (0) + 1" | calc.exe | grep -q '=> 0'
 // test: echo "quit" | calc.exe | grep -q 'bye'
old mode 100644 (file)
new mode 100755 (executable)
index 2660b43365569ceab2a284b811e3d59c99effeca..b7b74e230834129a77d98175ce20769930148c10 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -254,7 +254,7 @@ element_t *parser (char *str, char **next, int prio)
             (*str == '.') || (*str == '+') || (*str == '-')) {
             VERBOSE (DEBUG, PRINTOUT ("start processing value\n"));
             char *pt;
-            float value = strtof (str, &pt);
+            double value = strtod (str, &pt);
             VERBOSE (INFO, PRINTOUT ("Value: %f\n", value));
             if (str != pt) {
                 if (root == NULL) {
index 90dba49323fe032e7cfd7ce184d2d174a964bbdc..629b1b49a83272210f7faa1af41a7668506f54c9 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -30,7 +30,7 @@ typedef struct _element_t {
     func_t func;
     int nbops;
     struct _element_t *ops[MAX_OPERANDS];
-    float value;
+    double value;
     int prio;
 } element_t;