Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* double, double -> double
- * function fpu_add adds 2 double FP numbers
- */
- double fpu_add(double a, double b);
- double fpu_div(double a, double b);
- /* -> unsigned short (2B)
- * function get_fpu reads the FPU control word and returns it's value
- */
- unsigned short get_fpu();
- void set_fpu(unsigned short int);
- /*
- *
- */
- int main(int argc, char * argv[])
- {
- unsigned short int fpucw = 0x1234;
- double dbls[3] = {123.45, 0.123, 0.0};
- double dblx[3] = {123.45, 0.0, 0.0};
- /* generate double constants */
- unsigned long dbl = 0x4000000000000000;
- double * wsk = &dbl;
- //dbls[1] = *wsk;
- printf("unsigned long: %lx\n", dbl);
- printf("unsigned long: %lf\n", *wsk);
- /* add two numbers */
- dbls[2] = fpu_add(dbls[0], dbls[1]);
- printf("default: %lf + %lf = %lf\n", dbls[0], dbls[1], dbls[2]);
- fpucw = get_fpu();
- set_fpu(0xc7f); //changing precission
- /* add the same numbers as earlier to see difference */
- dbls[2] = fpu_add(dbls[0], dbls[1]);
- printf("default: %lf + %lf = %lf\n", dbls[0], dbls[1], dbls[2]);
- fpucw = get_fpu();
- set_fpu(0x7f); //changing exceptions
- /* add the same numbers as earlier to see difference */
- dblx[2] = fpu_div(dblx[0], dblx[1]);
- printf("dividing: %lf / %lf = %lf\n", dblx[0], dblx[1], dblx[2]);
- /* print FPU control word */
- fpucw = get_fpu();
- printf("FPU CW: %04hx\n", fpucw);
- /* Return 0 if exiting normally.
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement