Skip to content

Instantly share code, notes, and snippets.

@jacbar
Created April 26, 2011 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacbar/942547 to your computer and use it in GitHub Desktop.
Save jacbar/942547 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
#include <math.h>
int main() {
float in, ulamek;
uint64_t denominator = 1, numerator, sign;
scanf("%f",&in);
ulamek = in - floor(in);
while(ulamek > 0){
ulamek *= 10;
ulamek = ulamek - floor(ulamek);
denominator *= 10;
}
in >=0 ? sign = 0 : sign = 0x8000000000000000;
numerator = (int)(in * denominator);
printf("%d / %d\n",numerator, denominator);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment