4 ms·
> A floating point number is a method for storing decimal numbers... I'm sorry, what?
by haspok 2y ago
> A floating point number is a method for storing decimal numbers...
I'm sorry, what?
- ComSubVie 2y agoWhat do you mean? It's exactly that in almost any programming language. What is it you don't understand: "method" (a representation) or "decimal" (a number that consists of a whole and a fractional part)?
- actionfromafar 2y agoMaybe OP reacted because a float only looks like it is a way to store decimal numbers, when it's only an approximation of decimal numbers. If you really need decimal numbers you need something like mpmath¹. As a shorthand to explain what a float is to someone, "a decimal number" is an OK start though. But sometimes that approximation breaks down even for simple examples, i.e. 0.1 cannot be represented as a float. This can be quite unexpected if your mental model is that "floats are decimal numbers with a certain precision". 1: https://mpmath.org/ https://mpmath.org/
- haspok 2y agoYou cannot represent an arbitrary or fixed precision decimal number in a floating point format. Or to put it in another way: "Most decimal fractions cannot be represented exactly as binary fractions." - from the Python tutorial The word "decimal" does not simply mean "a number that consists of a whole and a fractional part".
- bajsejohannes 2y agoI agree with OP that it's unnecessarily confusing. A "method" is a procedure. The floating point number is the result of that procedure, not the procedure itself. "Decimal" implies a ten based system, even though it's perfectly fine to say "binary decimal". Using your own replacement words, it would be clearer to write "A floating point number is a representation of a number with a fractional part".
- dsego 2y agoMaybe it should've said "is a method of storing" instead of "for". It would make it clear it's not talking about a procedure, but a way or manner of doing something.
- dismalaf 2y agoSome programming languages differentiate between floats and decimals. But yeah, for laypeople, a float is a decimal.
- 3836293648 2y agoVery few numbers have decimals. They're not just numbers with whole and fractional parts, decimals are base 10 as well. .NET has them for monetary uses but I'm unaware of any other language(family) that has them built in.
- jdiff 2y agoIt may not be precise in its details but it's a very accessible explanation that's certainly "good enough." Maybe you could swap it in for "non-whole numbers" and still be reasonably accessible, but that's also not perfectly accurate since integers are stored just fine inside a float. I'm certainly not going to fault them for using layman terms when addressing laymen.
- tialaramex 2y agoIdeally for this work you want somebody who is capable of communicating in a way that doesn't feel dumbed down and yet also isn't actively wrong. This explanation of the floating point types does not hit that mark. I'm not in the market for an Odin book, so in some sense it doesn't matter what I think, but across fields it's better if what you're saying is able to both serve its immediate purpose and actually true. People are going to remember (some of) what you taught them and even if it felt peripheral at the time they may have centred it. When they return to this teaching again, it's not surprising that they assume you meant what you said, even if in your mind it was figurative or targeted at a superficial understanding of the subject. Decimal representations do exist in machines. Representations that can manage 1.2 exactly but can't handle a third, or pi, or the square root of 2 for example. But the floating point numbers aren't that, they're a weird (but useful) binary fraction and if we're going to mention them at all we need to make it clear what's going on here. For example the "float" (32-bit IEEE floating point type) called 1.2 is actually 5033165 divided by 4194304 which isn't actually six over five (1.2) but it's pretty close.
- karl_zylinski 2y agoHi, author here! I will update the book with a few clarifications surrounding my sloppy use of the word "decimal". As some have pointed out it is a bit of a "layman way" to view things, but nevertheless the reader should be made aware of whenever I use sloppy / simplified language.