eo icon indicating copy to clipboard operation
eo copied to clipboard

both `0.eq 0.0` and `0.0.eq 0` equal to `TRUE`

Open maxonfjvipon opened this issue 3 years ago • 7 comments

It happens because byte array of 0.0 and byte array of 0 have the same length equal to 8 (since all int objects cast to long in the core of eo) and these arrays are identical (they both consist of zeros). I think it's a bug because, for example, both 10.eq 10.0 and 10.0.eq 10 are FALSE

UPD: this behavior below is also weird: image

maxonfjvipon avatar Jul 27 '22 17:07 maxonfjvipon

@maxonfjvipon I don't think this is a bug since int and float are 8 bytes. But it's still a good issue. We need to add some kind of type checking. Maybe you have a solution?

Graur avatar Jul 28 '22 11:07 Graur

@Graur we can try to use sign bit for an indirect purpose. We can say that 0 is 0x00000000 and 0.0 is 0x80000000 (which is -0 in IEEE but we don't have -0 in EO). Then in java at place where we transform int or float to byte array we can add zero check.

I also thought about using 7 or 9 bytes array for 0, but it may break other code or cause integer overflow.

maxonfjvipon avatar Jul 28 '22 11:07 maxonfjvipon

@maxonfjvipon I think I like the idea about -0.0 (with an extra bit set to one)

yegor256 avatar Jul 28 '22 15:07 yegor256

@yegor256 ok, I'll try to implement it

maxonfjvipon avatar Jul 28 '22 15:07 maxonfjvipon

@yegor256 could you please tell me how I can run the test inside eo-runtime separately? I need to test and debug Param.asBytes() method

maxonfjvipon avatar Jul 29 '22 10:07 maxonfjvipon

@maxonfjvipon make a ticket, complain about the absence of documentation in README.

yegor256 avatar Jul 29 '22 11:07 yegor256

@maxonfjvipon The budget is 30 minutes

Graur avatar Jul 29 '22 14:07 Graur

@maxonfjvipon Thanks!

Graur avatar Aug 15 '22 14:08 Graur