version 1.6, 2000/12/05 01:24:52 |
version 1.9, 2015/08/06 10:01:52 |
|
|
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* |
* |
* $OpenXM: OpenXM_contrib2/asir2000/engine/real.c,v 1.5 2000/11/15 02:16:30 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/engine/real.c,v 1.8 2003/12/24 08:00:38 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "base.h" |
#include "base.h" |
|
|
double RatnToReal(a) |
double RatnToReal(a) |
Q a; |
Q a; |
{ |
{ |
double nm,dn,t,man; |
double nm,dn,man; |
int enm,edn,e; |
int enm,edn,e; |
unsigned int *p,s; |
|
|
|
nm = NatToReal(NM(a),&enm); |
nm = NatToReal(NM(a),&enm); |
if ( INT(a) ) |
if ( INT(a) ) |
if ( enm >= 1 ) |
if ( enm >= 1 ) { |
error("RatnToReal : Overflow"); |
error("RatnToReal : Overflow"); |
else |
/* NOTREACHED */ |
|
return 0; |
|
} else |
return SGN(a)>0 ? nm : -nm; |
return SGN(a)>0 ? nm : -nm; |
else { |
else { |
dn = NatToReal(DN(a),&edn); |
dn = NatToReal(DN(a),&edn); |
man = nm/dn; |
man = nm/dn; |
if ( SGN(a) < 0 ) |
if ( SGN(a) < 0 ) |
man = -man; |
man = -man; |
if ( ((e = enm - edn) >= 1024) || (e <= -1023) ) |
if ( ((e = enm - edn) >= 1024) || (e <= -1023) ) { |
error("RatnToReal : Overflow"); /* XXX */ |
error("RatnToReal : Overflow"); /* XXX */ |
else if ( !e ) |
/* NOTREACHED */ |
|
return 0; |
|
} else if ( !e ) |
return man; |
return man; |
else |
else |
return man*pow(2,e); |
return man*pow(2,e); |
|
|
#ifdef vax |
#ifdef vax |
t = m[0]; m[0] = m[1]; m[1] = t; itod(m); |
t = m[0]; m[0] = m[1]; m[1] = t; itod(m); |
#endif |
#endif |
#if defined(__i386__) || defined(MIPSEL) || defined(VISUAL) || defined(__alpha) || defined(__FreeBSD__) || defined(__NetBSD__) |
#if defined(__i386__) || defined(MIPSEL) || defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) || defined(__alpha) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__x86_64) |
t = m[0]; m[0] = m[1]; m[1] = t; |
t = m[0]; m[0] = m[1]; m[1] = t; |
#endif |
#endif |
return *((double *)m); |
return *((double *)m); |