Fix comparisons functions

Likely fixes fix issue [#8596](https://issues.dlang.org/show_bug.cgi?id=8596).
The existing code had issues with overflow and implicit narrowing conversion.