Comment Comment by huachimingo Which one is faster? (C code) Return: see if abs(num) > x./logical comparison/ int greater_abs(int num, int x){ return (num > x) || (num+x < 0); }/squared approach/ int greater_abs2(int num, int x){ return num*num > x; }See it by yourself, with (and without) optimizations: https://godbolt.org/What would happen if x is a compile-time constant? parent huachimingo 4 years ago
/logical comparison/ int greater_abs(int num, int x){ return (num > x) || (num+x < 0); }
/squared approach/ int greater_abs2(int num, int x){ return num*num > x; }
See it by yourself, with (and without) optimizations: https://godbolt.org/
What would happen if x is a compile-time constant?