replacement compare function for numbers

Hi there,
I am working on a project that requires me to compare two numbers. Is there a quick function like int r = a.compare(b) that returns -1 if the number is less than, 0 if its the same and +1 if it is greater?
Thanks,
Gav
No but you can easily create one yourself using relational operators (<, >, =, etc.).
r = std::min(1, std::max(-1, b-a));
r has a value of -1 if b is less than a.
r has a value of 0 if b is equal to a.
r has a value of 1 if b is greator than a.
Last edited on
Thanks guys.

@Zhuge Yeah I was going to do that if there was no simple function.

@LB thanks man. I'll give that a shot.
Topic archived. No new replies allowed.