[LAU] Need some programming help.

Tito Latini tito.01beta at gmail.com
Tue Nov 19 11:58:29 UTC 2013


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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

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:
> I've been slowing working my way though Yoshimi, looking for bugs and trying
> to understand the code, with some success. However, I've come across something
> that has me completely stumped.
> 
> On a modern machine if you look in the AdSynth edit window 'Detune' shows a
> variable number of trailing digits, where it should only show 2 after the
> decimal point. This is also true of all cases where a recalculated slider value
> is indirectly shown in an associated uneditable box. It happens nowhere else.
> 
> I've seen this on 64bit dual core AMDs and on 32bit Atoms. However, on an
> AthlonXP the problem doesn't occur.
> 
> At first I thought it might be due to different version of FLTK but having tried
> various releases of debian, from 'lenny' up to the current 'testing', the
> *only* differentiating feature I can discover is that the AthlonXP doesn't
> recognise the sse flag.
> 
> Finally, to add to the confusion, compiling on any of the other machines,
> without the sse flag set, still produces the fault - I'm wondering if even
> without this, some math feature is still being used that causes the fault.
> 
> Any help or suggestions would be gratefully welcomed!
> 
> -- 
> Will J Godfrey
> http://www.musically.me.uk
> Say you have a poem and I have a tune.
> Exchange them and we can both have a poem, a tune, and a song.
> _______________________________________________
> Linux-audio-user mailing list
> Linux-audio-user at lists.linuxaudio.org
> http://lists.linuxaudio.org/listinfo/linux-audio-user


More information about the Linux-audio-user mailing list