News for hackers. Stuff that matters.
Re:Formatting floating point numbers by bunderbunder on Friday June 14, 2019 @08:58AM (#20182574)
Fair enough.

One thing along similar lines that I've always hated to see is when the floating-point type in a programming language is called "real".

Re:Formatting floating point numbers by tomxor on Friday June 14, 2019 @09:22AM (#20182718)
haha, yes it's a terrible name, such arrogance to suggest fitting infinite things into a very finite thing. In fact they couldn't even call it rational, because even after the precision limitation it's a subset of rationals (where representation error comes from due to base)... Inigo Quilez cam up with a really interesting way around this limitation where numbers are encoded with a numerator and denominator, he called "floating bar", this essentially does not have representation error, but it will likely hit precision errors sooner or at least in a different way (it's kinda difficult to compare directly).
Re:Formatting floating point numbers by bunderbunder on Friday June 14, 2019 @10:13AM (#20183161)
Yeah, that is more what I'm on about. I can accept that a computer's `int` type is not an infinite set, even if it does cause problems at the boundaries. It feels like more of a little white lie to me.

Whereas, even between their minimum and maximum values, and even subject to their numeric precision, there are still so many rational numbers that an IEEE float can't represent. So it's not even a rational. Nor can it represent a single irrational number, thereby failing to capture one iota of what qualitatively distinguishes the real numbers. . . if Hacker News supported gifs, I'd be inserting one that features Mandy Patinkin right here.

Re:Formatting floating point numbers by tomxor on Friday June 14, 2019 @10:39AM (#20183364)
Yeah, I think this is the single aspect that everyone finds unintuitive, everyone can understand it not having infinite precision or magnitude. It's probably a very reasonable design choice if we could just know the reasoning behind it, I assume it will be mostly about practicality of performance and implementing the operators that have to work with the encoding.
Re:Formatting floating point numbers by romwell on Friday June 14, 2019 @09:31PM (#20187923)
>Inigo Quilez cam up with a really interesting way around this limitation where numbers are encoded with a numerator and denominator, he called floating bar

Thanks for the read! More fun than the original article to my taste :)

Here's the link, since Googling "floating bar" nets you very different results:

http://www.iquilezles.org/www/articles/floatingbar/floatingb...

Re:Formatting floating point numbers by tomxor on Saturday June 15, 2019 @04:26AM (#20188944)
I just remember his name, writes lots of interesting stuff :)
Re:Formatting floating point numbers by romwell on Monday June 17, 2019 @07:27PM (#20208310)
I always wonder if he ever says "My name is Inigo Quilez. Prepare to learn!".

My favorite post by him is where he explains that you never need to have trigonometry calls in your 3D engine. Because everyone now and then you still see "educational" article in the spirit of "learn trig to spin a cube in 3D!" :/

Re:Formatting floating point numbers by tomxor on Tuesday June 18, 2019 @01:05PM (#20215357)
Yeah, I've noticed in physics programming in other peoples code you can often come across the non-trig ways of doing things that avoid unit vectors and rooting etc (which are both elegant and efficient)... However i've never personally come across an explicit explanation or "tutorials" of these targeted at any level of programmer's vector proficiency. Instead i've always discovered them in code, and had to figure out how they work.

I guess the smart people writing a lot of this stuff just assume everyone will derive them as they go. That's why we need more Inigo Quilez's :D to lay it out for us mere mortals and encourage it's use more widely.

Re:Formatting floating point numbers by gumby on Friday June 14, 2019 @10:14AM (#20183169)
Common Lisp has had a rational number Type since the 1980s at least, presumably inherited from MACSYMA
Re:Formatting floating point numbers by astrobe_ on Friday June 14, 2019 @09:26AM (#20182753)
Then you should hate integer too.
Re:Formatting floating point numbers by tomxor on Friday June 14, 2019 @09:43AM (#20182909)
"integer" as a type is less offensive though, as it only has one intuitive deficiency compared the mathematical definition (finite range). Where as "real" as a type has many deficiencies... it simply does not contain irrational numbers, and it does not contain all rational numbers in 3 respects: range, precision and unrepresentable due to base2, and for integers it can represent a non-contiguous range!
Re:Formatting floating point numbers by ska on Friday June 14, 2019 @04:32PM (#20186439)
countable vs. uncountable deficiencies...
Re:Formatting floating point numbers by ben509 on Friday June 14, 2019 @03:33PM (#20185990)
But I can build a computer that would accept any pair of integers you sent it, add them and return the result. Granted, they'd have to be streamed over a network, in little-endian form, but unbounded integer addition is truly doable. And the restriction is implicit: you can only send it finite integers, and given finite time it will return another finite answer.

You can't say the same about most real numbers, all the ones that we postulate must exist but that have infinite complexity. You can't ever construct a single one of them.

Re:Formatting floating point numbers by Dylan16807 on Friday June 14, 2019 @09:50PM (#20187969)
I'm not sure what your point is. It's impossible to ask the computer to store those numbers, so why does it matter whether they can be stored?

Or in other words: It can store all the non-computable numbers you give it. That should suffice.

Re:Formatting floating point numbers by rwallace on Friday June 14, 2019 @06:25PM (#20187158)
The way I see it, 'int' as a truncation of 'integer' nicely symbolizes the way the type truncates integers to a fixed number of bits.

Of course any self-respecting modern language should also provide arbitrary-precision integers at least as an option.

Re:Formatting floating point numbers by astrobe_ on Saturday June 15, 2019 @10:58AM (#20190285)
It is not a matter of modernity, but a matter of use-case. You don't need arbitrary-length integers for a coffee machine or a fridge. You don't even need FP to handle e.g. temperatures; fixed-point is often more than enough. So if you are making some sort of "portable assembler" for IOT devices, you can safely stick with simple integers.