Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Well, ideally you'd want to treat int/int -> rational. The original form is quite obfuscated, some of the parentheses are to enforce evaluation of the given string as number (and the various programming languages will differ as what number that'll be, due to representation of decimal fractions and type conversion), some parenthesis are plainly superfluous, yet still there is remaining ambiguity (how is a%b/c to be interpreted? Most programming languages will do this left->right, but better make that explicit). Prefix notation to the rescue:

Common Lisp (with *read-default-float-format* -> SINGLE-FLOAT)

CL-USER> (+ (* (+ (* 788 8.46) (1- (* 8342 1.803))) 4186.4 15 (+ (* (/ (mod 22 284) (/ 7530 (* 2 (- 25 421) (mod 597 2663))))) 7283.8 -9.60 (mod 167.8644 3))) 8871)

8.03609e12

Wolfram Alpha finds for (((((((788)*(8.46))))+8342*1.803-1))*4186.4*(15))*(((mod [22, 284]/((7530/((2)*(((((25))-421))))))*mod[597, 2663])+7283.8-9.60+mod[167.8644, ((3))]))+(8871)

8.03609080242609957376254980079681274900398406374501992031872*10^12



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: