Skip to content

Instantly share code, notes, and snippets.

@drinkcat
Last active January 2, 2016 04:39
Show Gist options
  • Save drinkcat/8252415 to your computer and use it in GitHub Desktop.
Save drinkcat/8252415 to your computer and use it in GitHub Desktop.
#include <stdio.h>
/*
ARM output:
delay=45
delay=45
delay=97346
delay=-45
x86 output:
delay=45
delay=45
delay=97346
delay=-45
x86-64 output:
delay=45
delay=45
delay=-45
delay=-45
*/
#include <stdio.h>
long getdelay(long latencynsec, unsigned int rate) {
return latencynsec / rate;
}
long getdelay2(long latencynsec, unsigned int rate) {
return latencynsec / (long)rate;
}
int main() {
long delayp;
unsigned int rate = 44100;
delayp = getdelay(2000000, rate);
printf("delay=%ld\n", delayp);
delayp = getdelay2(2000000, rate);
printf("delay=%ld\n", delayp);
delayp = getdelay(-2000000, rate);
printf("delay=%ld\n", delayp);
delayp = getdelay2(-2000000, rate);
printf("delay=%ld\n", delayp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment