Re: [LAU] Need some programming help.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-audio-user@...>
Date: Tuesday, November 19, 2013 - 12:01 pm

You could try the follow command

cc -o precision_test -lm precision_test.c

uname -p
AMD Phenom(tm) II X6 1090T Processor

# Usage: precision_test step
./precision_test 0.01 | column -t
A 1.000000000000
B 100.000000000000
A/B 0.010000000000
precision 2

If your output is different, there is a round off problem, I presume
with `rint'.

/* precision_test.c */
#include
#include
#include
#include
#include

int main(int argc, char **argv)
{
double A, B, s;
int i, c = 0;
char temp[32];

if (argc < 2) return 1;
s = atof(argv[1]);
/* Used in `Fl_Valuator::step' */
A = rint(s);
B = 1;

while (fabs(s-A/B) > 4.66e-10 && B<=(0x7fffffff/10)) {
B *= 10;
A = rint(s*B);
}
/* Used in `Fl_Valuator::format' to calculate the precision for snprintf */
snprintf(temp, sizeof(temp), "%.12f", A/B);

for (i=(int) strlen(temp)-1; i>0; i--)
if (temp[i]!='0') break;

for (; i>0; i--, c++)
if (!isdigit(temp[i])) break;

printf("A %.12f\nB %.12f\nA/B %.12f\nprecision %d\n", A, B, A/B, c);
return 0;
}

On Mon, Nov 18, 2013 at 09:14:44PM +0000, Will Godfrey wrote:

_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-user

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[LAU] Need some programming help., Will Godfrey, (Mon Nov 18, 9:14 pm)
Re: [LAU] Need some programming help., Tito Latini, (Tue Nov 19, 12:01 pm)
Re: [LAU] Need some programming help., Will Godfrey, (Thu Nov 21, 7:22 pm)
Re: [LAU] Need some programming help., Tito Latini, (Fri Nov 22, 12:36 am)
Re: [LAU] Need some programming help., Will Godfrey, (Sun Mar 2, 11:19 pm)
Re: [LAU] Need some programming help., Tito Latini, (Mon Mar 3, 5:59 pm)
Re: [LAU] Need some programming help., Will J Godfrey, (Mon Mar 3, 6:50 pm)
Re: [LAU] Need some programming help., James Morris, (Tue Nov 19, 12:53 am)