The following code :

double midiToFreq(double note) 

{

    return 440.0 * pow(2.0, (note-69.0)/12.0);

}


float midiToFreq2(float note) 

{

    return 440.0f * powf(2.0f, (note-69.0f)/12.0f);

}


int main()

{

    for (int i = 48; i < 84; i++) {

        printf("pitch %d %f\n", i, midiToFreq(i));

        printf("pitch %d %f\n", i, midiToFreq2(i));

    }

}

correctly gives :

pitch 48 130.812783
pitch 48 130.812775
pitch 49 138.591315
pitch 49 138.591324
pitch 50 146.832384
pitch 50 146.832382
pitch 51 155.563492
pitch 51 155.563492
pitch 52 164.813778
pitch 52 164.813782
pitch 53 174.614116
….

when compiled with a C compiler and incorrectly gives the following when 
compiled with emcc and displayed in JS : 

pitch 48 130.812783
pitch 48 130.812783
pitch 49 138.591315
pitch 49 136.604359
pitch 50 146.832384
pitch 50 148.968110
pitch 51 155.563492
pitch 51 155.563492
pitch 52 164.813778
pitch 52 162.450876
pitch 53 174.614116
pitch 53 177.153937
pitch 54 184.997211

When could be the reason for this strange behavior of the powf function ?

Thanks.

Stéphane Letz

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to