top | item 42388382

(no title)

ComSubVie | 1 year ago

What 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)?

discuss

order

haspok|1 year ago

You 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|1 year ago

I 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|1 year ago

Maybe 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.

actionfromafar|1 year ago

Maybe 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/

dismalaf|1 year ago

Some programming languages differentiate between floats and decimals. But yeah, for laypeople, a float is a decimal.

3836293648|1 year ago

Very 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.