mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-05 13:30:00 -05:00
control: use more precise rounding in snd_ctl_ascii_value_parse()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
409cea0759
commit
d39f5acd9b
1 changed files with 11 additions and 8 deletions
|
|
@ -33,17 +33,20 @@
|
|||
|
||||
/* Function to convert from percentage to volume. val = percentage */
|
||||
|
||||
#ifdef HAVE_SOFT_FLOAT
|
||||
static inline long int convert_prange1(long val, long min, long max)
|
||||
static inline long int convert_prange1(long perc, long min, long max)
|
||||
{
|
||||
long temp = val * (max - min);
|
||||
return temp / 100 + min + ((temp % 100) == 0 ? 0 : 1);
|
||||
}
|
||||
#else
|
||||
long tmp;
|
||||
|
||||
#define convert_prange1(val, min, max) \
|
||||
ceil((val) * ((max) - (min)) * 0.01 + (min))
|
||||
#ifdef HAVE_SOFT_FLOAT
|
||||
tmp = perc * (max - min);
|
||||
tmp = tmp / 100 + ((tmp % 100) < 50 ? 0 : 1);
|
||||
#else
|
||||
tmp = rint((double)perc * (double)(max - min) * 0.01);
|
||||
#endif
|
||||
if (tmp == 0 && perc > 0)
|
||||
tmp++;
|
||||
return tmp + min;
|
||||
}
|
||||
|
||||
#define check_range(val, min, max) \
|
||||
((val < min) ? (min) : ((val > max) ? (max) : (val)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue