govaluate icon indicating copy to clipboard operation
govaluate copied to clipboard

comparison of ints

Open TheZeroSlave opened this issue 6 years ago • 2 comments

Hello. I checked that all numeric values are casted to float64 when parsed into tokens. It seems not right since float comparison of the same values can fail. i.e. '1+1 == 2' may be not true. because '1+1' may become 1.9999999999999998 in float or am i wrong?

TheZeroSlave avatar Apr 16 '18 16:04 TheZeroSlave

You're correct, every numeric value is treated as float64 regardless of what type it was initially, and also yes, there's no epsilon-based equality checking for integers (internally, the == operator calls reflect.DeepEquals, which just turns into a standard Go == check against float64's).

I'm not opposed to building in an epsilon-based special check for numeric values, but I'm not entirely sure what the use case would be. It may sound silly, but I've actually never needed to check if 1+1 is actually strictly equal to 2. Was there an expression you were using that led to this?

Knetic avatar Jun 17 '18 19:06 Knetic

@Knetic in my case x%10==8, when x is 71111112902814738, the result is wrong, alse this reason?

btfak avatar Sep 03 '19 12:09 btfak