Live data from Hacker News

9999999999999999.0 – 9999999999999998.0

geocar.sdf1.org

71–80 of 83 posts

Re: 9999999999999999.0 – 9999999999999998.0

#71

Floating point 101. And it almost never matters.

You say that, and then an army of idiots out in the real world continues to use floats for financial data and other large integers. I ran into a site that broke because they were using 64b unix nanotime in Javascript and comparing values which were truncated. You see this in js, python, etc. constantly.

For the JS case, that's really JavaScript's fault, since double-precision float ("number") is the only built in numeric type, other that BigInt, which has only existed for a few years.

Re: 9999999999999999.0 – 9999999999999998.0

#72
post #5

Floating point 101. And it almost never matters.

> And it almost never matters. I take issue with this. Drift from floating point inaccuracies can compound quickly and dramatically affect results. Sure if you're just looping over a 1000 item list, it's not going to matter that JavaScript is representing that as a float/double, but in a wide variety of contexts, such as anything to do with money, it absolutely does matter.

Oh for 9999999999999999 pennies! I wouldn't care if I got one less that I was supposed to! :-)

Re: 9999999999999999.0 – 9999999999999998.0

#73
post #69
post #67

Earlier quoted context omitted.

I consider myself an old unix person, but I use dc. Possibly to make it more confusing to anyone who looks at what I'm doing. It also gives the math result here of course. % dc 9999999999999999.0 9999999999999998.0 - p 1.0 %

rpn for for the win I guess ;-). I actually didn't get to try my first linux stuff until grad school in the 80s. I wish I had saved off all my init files from then to see what they look like now.

Back in the day (Unix Seventh Edition) bc was just a front end that compiled the expression and piped it to dc. My take it is most people didn't find rpn a win, and bc was the fix.

I used bc's compiled output ("bc -c") to learn how to make dc jump through hoops.

https://man.cat-v.org/unix_7th/1/bc

Re: 9999999999999999.0 – 9999999999999998.0

#74
post #66
post #10

bc -l is my standard command-line tool for arbitrary precision calculations (-l not needed here but handy for functions like sqrt(), e(), and log l() ): $ bc -l bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 9999999999999999.0 - 9999999999999998.0 1.0

I got tired of typing bc -l years ago, I have a function so I can do it on the command line: calc 2^27 + 3^15. I wish somehow the shell would let me add parens here, instead of having to escape them with a quote. function calc2 { if [ $# -eq 0 ]; then echo 'pass commands for math evaluation, like calc l(2^32/17) + 3'; fi; echo $* | bc -l; }

This is what I've had in my bashrc for a few years:

= () { printf "%'.f\n" $(echo $1 | bc); }; alias calc==

Re: 9999999999999999.0 – 9999999999999998.0

#75
post #67
post #63

Earlier quoted context omitted.

who does not use bc? people who aren't old unix people ;-) I use bc

I consider myself an old unix person, but I use dc. Possibly to make it more confusing to anyone who looks at what I'm doing. It also gives the math result here of course. % dc 9999999999999999.0 9999999999999998.0 - p 1.0 %

I guess old unix persons do use bc. But even older unix persons, like you and me, use dc. Oh, and I still have my trusty old HP48GX calculator that I bought nearly thirty years ago. Algebraic notation is fine for paper, bur RPN is best for calculating. I am glad I can even have an RPN calculator (PCalc) on my phone now.

Re: 9999999999999999.0 – 9999999999999998.0

#77
In Ada:

    with Ada.Text_IO; use Ada.Text_IO;
    procedure Example is
    begin
        Put_Line (Float (9999999999999999.0-9999999999999998.0)'Image);
    end Example;
Result:

     1.00000E+00
If I really wanted to, I could use a decimal instead, e.g.

    with Ada.Text_IO; use Ada.Text_IO;
    procedure Example is
        type Decimal is delta 1.0E-20 digits 38;
    begin
        Put_Line (Decimal (9999999999999999.0-9999999999999998.0)'Image);
    end Example;
Result:

     1.00000000000000000000

Re: 9999999999999999.0 – 9999999999999998.0

#78
post #54

Nim gives the wrong answer (2.0). I've posted this to the Nim forum: https://forum.nim-lang.org/t/10866#72441

To be clear, Nim is going to be beholden to the platform C implementation it is compiled on for its floating point behavior.

I thought that may be the case.

Re: 9999999999999999.0 – 9999999999999998.0

#79

Emacs Calculator with high precision will get you what you need (`M-x calc RET P 20 RET 9999999999999999.0 RET 9999999999999998.0 RET -` gives you `1.`) Definitely keeping this example in my back pocket for explaining to people why floating point is not what you think it is.

That reminds me, emacs was truly the best Operating System.
Post reply on HN