News for hackers. Stuff that matters.
Re:It’s COBOL all the way down by ibiza on Tuesday May 01, 2018 @09:32AM (#16966874)
It gives you correct answers to simple questions like this:

    > console.log(0.1 * 0.1)
    0.010000000000000002
Re:It’s COBOL all the way down by trcollinson on Tuesday May 01, 2018 @10:17AM (#16967193)
I’m not sure I get your joke. Every system, JavaScript, COBOL, C, Java, etc etc etc, has this behavior. Floating point decimals when converted to binary, are a rather rough thing for a system to handle. For example, 0.1 in binary is a repeating number. Basic operations on those binary values are very very fast but not always 100% accurate due to the binary nature of decimals. There are packages which allow for very precise floating point calculations but will cause performance degradation compared to the basic operations. It all depends on what you need.
Re:It’s COBOL all the way down by wolfgang42 on Tuesday May 01, 2018 @11:13AM (#16967670)
COBOL uses fixed-point decimal arithmetic, not binary floating-point. You'd declare these variables as PIC V99 and then get a nice neat .10×.10=.01 (or as PIC 99V999 and get 00.100×00.100=00.010, or whatever). This is because it's a Business-Oriented Language, and businesses don't want floating point rounding errors in their finances.

Incidentally, this was actually faster than binary floating-point on the machines for which COBOL was designed, which used EBCDIC and had special circuitry for arithmetic on binary-coded-decimal numbers. You could operate directly on the decimal representation without having to do any conversion for I/O.

Re:It’s COBOL all the way down by rst on Tuesday May 01, 2018 @12:56PM (#16968847)
Nit: the COBOL spec dates to 1960; EBCDIC came later, ~1963. In 1960, character codes were specific to the manufacturer, and sometimes to the machine. IBM had a 6-bit BCD code that was mostly consistent across its line, but Univac had its own which was quite different.
Re:It’s COBOL all the way down by amelius on Tuesday May 01, 2018 @12:08PM (#16968314)
Intel x86 can also work natively with BCD numbers.

https://en.wikipedia.org/wiki/Intel_BCD_opcode

Re:It’s COBOL all the way down by bashook on Tuesday May 01, 2018 @01:27PM (#16969177)
Very cool. Unfortunately it's no longer supported in Long mode (x86-64). :-(
Re:It’s COBOL all the way down by upofadown on Tuesday May 01, 2018 @04:13PM (#16971050)
I used to do a lot of BCD in embedded POS stuff. No one will miss it. You can do anything you can do in BCD with regular integers if you have any understanding of integer arithmetic. Yeah, it is going to take a little more time to convert to/from decimal digits you can display/input but processors these days have fast integer division so that doesn't matter.

A current issue is that a lot of programmers are bad at integer arithmetic. It isn't really taught in school.

Re:It’s COBOL all the way down by amelius on Tuesday May 01, 2018 @10:53AM (#16967467)