mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-19 12:16:59 +00:00
MINOR: tools: add new round_2dig() function to round integers
This function rounds down an integer to the closest value having only 2 significant digits.
This commit is contained in:
parent
8c97ab5eb2
commit
3ca1a883f9
@ -242,6 +242,8 @@ static inline int hex2i(int c)
|
||||
return c;
|
||||
}
|
||||
|
||||
/* rounds <i> down to the closest value having max 2 digits */
|
||||
unsigned int round_2dig(unsigned int i);
|
||||
|
||||
/*
|
||||
* Checks <name> for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an
|
||||
|
@ -504,6 +504,18 @@ int ishex(char s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* rounds <i> down to the closest value having max 2 digits */
|
||||
unsigned int round_2dig(unsigned int i)
|
||||
{
|
||||
unsigned int mul = 1;
|
||||
|
||||
while (i >= 100) {
|
||||
i /= 10;
|
||||
mul *= 10;
|
||||
}
|
||||
return i * mul;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks <name> for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an
|
||||
* invalid character is found, a pointer to it is returned. If everything is
|
||||
|
Loading…
Reference in New Issue
Block a user