i'm saying it'd be nice if i didn't have to write ...
# announcements
h
i'm saying it'd be nice if i didn't have to write
toDouble()
all over my mathematics in kotlin 😑
k
Okay but that's for both of my above cases, do you want both to go to doubles?
h
automatically, yeah
k
The first one I understand, I agree that it's annoying without any real safety benefits.
h
also, is double just a float with twice the memory allocated?
k
But
3 / 2
is just integer arithmetic and we need that too.
h
i know i learned that at one point, but forgot it, because i learned it before it was of any practical use to me
k
(Yes, double is float with more bits)
h
meaning you want
3/2
to round to remain as an int?
k
Yes, I use that a lot.
h
ah, good point
i guess i never considered it because in java you have to use ceiling and cast back to int
or i think casting back to int does that by itself now that i think about it..
k
No, it's the same in Java and every other C-like language there is.
Not even a cast, that's literally what / on its does.
h
nvm me then... i'm dumb!
k
That's also what the dedicated CPU instruction does :)
h
i just like my math equations in my code to be devoid of much other than variables, numbers, and mathematical operators
the casting distracts the eye from the important parts
c
Just write it with the decimal point 3.0 / 2.0
Otherwise it would think you are working with int and not double
h
maybe the same reason i don't like
!foo.isEmpty
and prefer
foo.isNotEmpty
yeah, you're very correct, Chris
but that doesn't work if your integers are stored as variables
c
Oh so you mean wanting to divide ints with a double result
h
Copy code
val foo = 3
val bar = .3
println(foo + bar)
does not compile
c
Yeah need to cast one of them
h
i've been dissuaded from dividing ints into automatic doubles
c
I still rather cast, type conversion should be explict
h
maybe i just like java's casting more than kotlin's?
c
Talking as vs a cstyle cast
h
(int)
is a lot less verbose than
toInt()
or
as Int
but i get it
there's no perfect solution here, and i appreciate hearing the counter-arguments
c
Yeah I am pretty used to the c style ones
Not sure about kotlin but in C#
(T)
has a different meaning then
as T
as well
k
Btw if you're really frustrated about this you can define/generate code like
inline operator fun Double.plus(other: Int) = this + other.toDouble()
and friends.
h
okay, thanks, Karel! you're so helpful
c
just be sure that is known and does not confuse the crap out of the rest of the devs on the project