Zoltan Demant
07/10/2023, 12:22 PMSam
07/10/2023, 12:25 PMJoffrey
07/10/2023, 12:26 PMZoltan Demant
07/10/2023, 12:32 PMJoffrey
07/10/2023, 12:33 PMWhenever I work with fractions, float values make the most sense to me. 0.1f = 10% etc.I'm sorry I don't get that, why not just
0.1
(a double) instead of 0.1f
(a less precise float)?Zoltan Demant
07/10/2023, 12:36 PM@Composable
fun CircularProgressIndicator(
progress: Float,
)
Joffrey
07/10/2023, 12:44 PMIts the pattern Ive come to know over too many yearsWhat pattern? You might be missing my point.
Double
is also a IEEE 754 floating-point value, just like Float
, but it's 64bit instead of 32bit, which is more precise and can represent larger numbers. It's also the default for decimal literals like 0.1
(unless you force the less precise 32-bit Float
type by adding an f
). That's why I was asking this question.
More info: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.htmlDouble
instead of Float
in your composable example, and drop the f
suffixes in your literals, and everything would work the same (but with more precision)Zoltan Demant
07/10/2023, 1:02 PMJoffrey
07/10/2023, 1:03 PMMervyn McCreight
07/10/2023, 1:03 PMbut it's 64bit instead of 32bit
- i think the language should not force you to use doubles. what if i’m fully aware of what a float is and i decide that this is all i need for my use-case?yschimke
07/10/2023, 2:02 PMJoffrey
07/10/2023, 2:02 PMwhat if i’m fully aware of what a float is and i decide that this is all i need for my use-case?Then... just use a
Float
?the language should not force you to use doublesIt doesn't. You still have the option to use the
Float
type, it's not even deprecated.
But the language should definitely make it more convenient to do the right thing, and avoid making the wrong things easy to do. So if the right thing is to use Double
most of the time (unless you have special requirements) then the current state is a good thing. If you have those special requirements, then you should know how you want to sum up your floats and deal with the imprecision.Fleshgrinder
07/12/2023, 5:47 AMInt
ought to be a Long
and that the language is doing it wrong right now... not sure if...yschimke
07/12/2023, 6:08 AMFleshgrinder
07/12/2023, 6:19 AMBigDecimal
is more precise than double, it does not follow that we should use it everywhere. These are all trade offs. In case of integers we trade space for range and in case of floats we trade space for precision. The right choice depends. Otherwise there wouldn't be types like f8
, f16
, ... That the JVM only knows i32
, i64
, f32
, and f64
doesn't mean that other ranges or precisions are bad, it's a JVM design decision. Summing a bunch of floats might be perfectly fine, might be entirely wrong, it depends...