Project

General

Profile

Bug #5224 » tmul.c

Richard PALO, 2014-10-19 01:15 PM

 
1
#include <stdio.h>
2
#include <ieeefp.h>
3
#include <float.h>
4

    
5
double
6
my_mul_set(double x, double y, int *pe) {
7
	int sw;
8
	double z;
9
	extern void _putsw(int);
10
	extern void _getsw(int*);
11
	_putsw(0);
12
//	__asm__ volatile ("fnclex" );
13
	z = x * y;
14
	_getsw(&sw);
15
//	__asm__ volatile ("fstsw (%0)" : : "r"(&sw) );
16
	if ((sw & 0x3f) == 0) {
17
		*pe = 0;
18
	} else {
19
		/* Result may not be exact. */
20
		*pe = 1;
21
	}
22
	return z;
23
}
24
extern double __mul_set(double,double,int*);
25
int main()
26
{
27
	volatile const double onethird = 1.0/3.0;
28
	const double p17 = 1.0e17;
29
	int pe;
30
	double result;
31
	long double lresult;
32

    
33
	if (fpgetround() != FP_RN){
34
		fpsetround(FP_RN);
35
	}
36

    
37
	result = my_mul_set(onethird, p17, &pe);
38
	if (pe)
39
		printf("ATTENTION: My result may be inexact!\n");
40
	
41
	printf("my_mul_set initial = %.*f => result: %f\n", DECIMAL_DIG, onethird, result);
42
	printf("---------------------------------------\n");
43
	result = __mul_set(onethird, p17, &pe);
44
	if (pe)
45
		printf("ATTENTION: Libc result may be inexact!\n");
46
	printf("__mul_set initial = %.*f => result: %f\n", DECIMAL_DIG, onethird, result);
47

    
48
	return 0;
49
}
(4-4/5)