3 ms·
> Int.abs can return a negative number. The documentation for abs[1] explains: "Warning. This may be negative if the argument is Int.min_int." I think that's
by omoikane 4y ago
> Int.abs can return a negative number.
The documentation for abs[1] explains: "Warning. This may be negative if the argument is Int.min_int."
I think that's just the nature of two's complement and not necessarily a fault of OCaml. C++ is also like that[2].
[1] https://v2.ocaml.org/api/Int.html https://v2.ocaml.org/api/Int.html
[2] https://gcc.godbolt.org/z/34b3GbvvT https://gcc.godbolt.org/z/34b3GbvvT
- anderskaseorg 4y agoIn C and C++, abs(INT_MIN) is undefined behavior. (C17 §7.22.6.1: “The abs, labs, and llabs functions compute the absolute value of an integer j. If the result cannot be represented, the behavior is undefined.” Footnote: “The absolute value of the most negative number cannot be represented in two’s complement.”)
- yawaramin 4y agoHonestly the way OP just throws out a scary-sounding 'well this is an obvious bug that abs can return a negative number', without giving the context that it's for the minimum value of a machine int type, really says it all. He doesn't have an interest in evaluating it fairly, he's just doing a hit piece.