Hullaballoonatic
12/03/2019, 9:23 PMByte
is a Number
, then why isn't a Bit
/`Boolean`?
Iirc, Boolean
isn't actually stored with just one bit in memory, but does that actually matter?Ruckus
12/03/2019, 9:29 PMByte
represents numeric values and can perform numeric operations. Boolean
doesn't.Hullaballoonatic
12/03/2019, 9:30 PMBoolean
logically equivalent to a Bit
, which is a numberstreetsofboston
12/03/2019, 9:35 PMChar
is not a Number
Ruckus
12/03/2019, 9:36 PMBit
is a number? (Also, Bit
isn't a type in Kotlin, so that comparison doesn't really apply here).Hullaballoonatic
12/03/2019, 9:36 PMChar::toInt
?Byte
is a number, the same can be applied to a Bit
Bit
does exist in Kotlin. it's just called Boolean
Ruckus
12/03/2019, 9:38 PMBit
. If you define it to be Boolean
, then it has nothing to do with Byte
.Hullaballoonatic
12/03/2019, 9:39 PMRuckus
12/03/2019, 9:40 PMBoolean
. A Boolean
is true
or false
. Not 1
or 0
. They may be represented the same in memory, but that's irrelevant.Hullaballoonatic
12/03/2019, 9:41 PMRuckus
12/03/2019, 9:42 PMBit
is numerical. You seem to be operating off the assumption that 1 === true
and 0 === false
, which isn't true.
(Sorry, I started writing that before I saw your message)Hullaballoonatic
12/03/2019, 9:42 PMRuckus
12/03/2019, 9:43 PMHullaballoonatic
12/03/2019, 9:44 PMRuckus
12/03/2019, 9:44 PMBit
were defined, it could be done in a way that makes it logical and numerical. Boolean
just isn't.Hullaballoonatic
12/03/2019, 9:48 PM&&
differently from the bitwise and/&
? Shouldn't true xor false
compile? It doesn't because true and false are not bitwise values, but in boolean logic if two statements have identical truth tables, they are logically equivalent; bitwise and
and logical &&
have identical truth tables. Same goes for all bitwise and boolean unary and binary functionsRuckus
12/03/2019, 9:49 PM1 == true
and 0 == false
, but in others that's not true. Even if they are represented the same internally, it often makes sense (especially in strongly typed languages) to have them be semantically separated.Hullaballoonatic
12/03/2019, 9:50 PMRuckus
12/03/2019, 9:50 PMxor
is there, but not nand
or`nor`.Hullaballoonatic
12/03/2019, 9:50 PMxor
.Boolean::xor
?Ruckus
12/03/2019, 9:51 PMHullaballoonatic
12/03/2019, 9:51 PMand
and or
are exclusive to bitwise operationsRuckus
12/03/2019, 9:54 PMBit
type that is both numerical and logical and handles conversion to/from number types.Hullaballoonatic
12/03/2019, 9:56 PMRuckus
12/03/2019, 9:56 PMtrue == 1
but true !== 1
...Hullaballoonatic
12/03/2019, 9:59 PMRuckus
12/03/2019, 10:00 PMHullaballoonatic
12/03/2019, 10:00 PMBoolean
would just extend Number
and be comparable to other `Number`s.===
vs ==
distinction is in kotlin. I initially assumed ===
meant equal hashcodes or that they must be the same javaclass, and that ==
was using compareTo
operator, but that is not the case.streetsofboston
12/03/2019, 10:04 PM===
compares the instance reference.==
executes the equals
methodRuckus
12/03/2019, 10:05 PMHullaballoonatic
12/03/2019, 10:05 PMoperator compareTo
to compare equivalency between 2 instances is to do x.compareTo(y) == 0
? That's pretty sillystreetsofboston
12/03/2019, 10:05 PM==
and ===
are the same==
should suffice for equivalency.Hullaballoonatic
12/03/2019, 10:06 PMwhen(myLong) {
0 -> ... // type mismatch Int/Long
1 -> ... // type mismatch Int/Long
else -> ...
}
streetsofboston
12/03/2019, 10:07 PMequals
takes an Any?
as input parameter….Hullaballoonatic
12/03/2019, 10:07 PMstreetsofboston
12/03/2019, 10:08 PMwhen
clause by the compiler…. Wonder if the Number#equals
enforces the receiver and the input parameter to be of the same class.Ruckus
12/03/2019, 10:08 PMequals
function for primitives on the JVM.streetsofboston
12/03/2019, 10:09 PMHullaballoonatic
12/03/2019, 10:09 PMstreetsofboston
12/03/2019, 10:12 PMmyLong == 0
, which won’t compile with myLong.equals(0)
, which does compile, but still complainsequals
is implemented for a java.lang.Long:
public boolean equals(Object obj) {
if (obj instanceof Long) {
return value == ((Long)obj).longValue();
}
return false;
}
Ruckus
12/03/2019, 10:15 PMstreetsofboston
12/03/2019, 10:15 PMLong
, it will return false. Since it will always be false, myLong == myInt
will not compile, since it always will return false
…Hullaballoonatic
12/04/2019, 5:22 PMChar
is a Number
in Kotlinstreetsofboston
12/04/2019, 5:23 PMpublic class Char private constructor() : Comparable<Char>
Hullaballoonatic
12/04/2019, 5:23 PMtoChar