Ray Rahke
04/21/2024, 1:50 PMvar x: Number = 2
var y: Number = 3
var c = x + y
it is so annoying that this is not accepted in kotlinJoffrey
04/21/2024, 1:50 PMNumber
type?Ray Rahke
04/21/2024, 1:52 PMRay Rahke
04/21/2024, 1:53 PMRay Rahke
04/21/2024, 1:53 PMfn(5)
bu also fn(5.9)
Ray Rahke
04/21/2024, 1:54 PMx: Int | Double
union typesRay Rahke
04/21/2024, 1:54 PMplayer.health -= 5
Ray Rahke
04/21/2024, 1:54 PMRay Rahke
04/21/2024, 1:55 PMplayer.health -= 5.0
Ray Rahke
04/21/2024, 1:55 PMJoffrey
04/21/2024, 1:55 PMRay Rahke
04/21/2024, 1:56 PMRay Rahke
04/21/2024, 1:57 PMRay Rahke
04/21/2024, 1:57 PMRay Rahke
04/21/2024, 1:57 PMRay Rahke
04/21/2024, 1:58 PMRay Rahke
04/21/2024, 1:59 PMRay Rahke
04/21/2024, 1:59 PMJoffrey
04/21/2024, 2:06 PMand then it goes "woops! you need to use a double!"
It doesn't. You can totally do this. https://pl.kotl.in/nnmxU1HGP
Ray Rahke
04/21/2024, 2:09 PMRay Rahke
04/21/2024, 2:10 PMRay Rahke
04/21/2024, 2:10 PMJoffrey
04/21/2024, 2:33 PMNumber
for your types, if your function manipulates numbers that can be non-integers, just use double or float, so the operations you do are clearly defined in terms of overflow and return type. If you're fine with languages like JS that don't distinguish different number types, then you pretty much get doubles everywhere, so the argument about ints is moot. In general though, we want to be aware of the precision or overflows of the operations we perform. So we use distinct types and explicit conversions where it makes senseArjan van Wieringen
04/21/2024, 5:49 PMLandry Norris
04/21/2024, 6:48 PMShawn
04/22/2024, 4:53 AMCLOVIS
04/23/2024, 10:33 AMthe vast majority of the time that I am annotating a function parameter or a class field as something numerical, it is indifferent to whether it is a float or integerAs long as you have that attitude, please don't work in finance or any other critical fields. And read a bit on floating point arithmetic.