signbit question
Stefan Koch
uplink.coder at googlemail.com
Thu Mar 15 16:31:56 UTC 2018
On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote:
> Why does std.math.signbit only work for floating point types?
> Is there an analogue function for integer types? what is the
> best way to compare the sign of a float with the sign of an
> integer?
> Thanks in advance
integers don't have a sign-bit.
since they are not necessarily singed.
However if an integer is signed and using 1-complement
you can either do sign = var < 0 or
sign = (var & (1 << (sizeof(var)*8 - 1));
though I cannot tell which one is faster you have to experiment.
More information about the Digitalmars-d-learn
mailing list