compiler/bootstrap/unix-88/Reals.c
David C W Brown da88496c5f Tidy (#41)
* Deduplicate common constants into OPM and do some source format tidying.

* Fix postpush buildall script to force checkout of updated buildall.

* Show enlistment branch in makefiles

* Support non-printables in string literals and tidy case alignment and constant literals.

* Common code for MIN and MAX of integer types.

* Common code for SInt/Int/LInt in ConstOp parameter preparation.

* Common code for SInt/Int/LInt in Op parameter preparation.

* Refactor SetIntType to work with byte size directly. Prepare to revert my incorrect VAL changes.

* Original meaning of VAL restored. Many library files disabled until use of VAL in 64 bits fixed.

* Make Reals.Mod independent of INTEGER size and add reals tests.

* Implement fraction, IsInfinity and IsNaN in oocLowReal.Mod.

* OPB little simplifications and ShorterSize/LongerSize functions.

* Add test for alignment computability

* Replace alignment constants with calculated alignment.

* typ.size aware OPV.Convert

* Add SYSTEM_INT64 and make tests name independent.

* Remove SYSTEM.H includes (string.h and stdint.h).

* Replace uses of uintptr_t and size_t with SYSTEM_ADDRESS.

* Sad hack to make FreeBSD and OpenBSD happy with memcpy declaration.

* Detect 64 bit on FreeBSD, and size_t defined on OpenBSD.

* %zd not supportd by mingw, cast strnlen return to int.

* Add debug for intermittent failure only on OpenBSD.

* Add textTexts as a confidence test and tidy up a couple of other tests.

* Update binary test process.
2016-08-25 14:41:00 +01:00

150 lines
3.2 KiB
C

/* voc 1.95 [2016/08/23] for gcc LP64 on cygwin xtspkaSfF */
#define LARGE
#include "SYSTEM.h"
static void Reals_BytesToHex (SYSTEM_BYTE *b, LONGINT b__len, SYSTEM_BYTE *d, LONGINT d__len);
export void Reals_Convert (REAL x, INTEGER n, CHAR *d, LONGINT d__len);
export void Reals_ConvertH (REAL y, CHAR *d, LONGINT d__len);
export void Reals_ConvertHL (LONGREAL x, CHAR *d, LONGINT d__len);
export void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len);
export INTEGER Reals_Expo (REAL x);
export INTEGER Reals_ExpoL (LONGREAL x);
export void Reals_SetExpo (REAL *x, INTEGER ex);
export REAL Reals_Ten (INTEGER e);
export LONGREAL Reals_TenL (INTEGER e);
static CHAR Reals_ToHex (INTEGER i);
REAL Reals_Ten (INTEGER e)
{
REAL _o_result;
LONGREAL r, power;
r = (LONGREAL)1;
power = (LONGREAL)10;
while (e > 0) {
if (__ODD(e)) {
r = r * power;
}
power = power * power;
e = __ASHR(e, 1);
}
_o_result = r;
return _o_result;
}
LONGREAL Reals_TenL (INTEGER e)
{
LONGREAL _o_result;
LONGREAL r, power;
r = (LONGREAL)1;
power = (LONGREAL)10;
for (;;) {
if (__ODD(e)) {
r = r * power;
}
e = __ASHR(e, 1);
if (e <= 0) {
_o_result = r;
return _o_result;
}
power = power * power;
}
__RETCHK;
}
INTEGER Reals_Expo (REAL x)
{
INTEGER _o_result;
INTEGER i;
__GET((LONGINT)(SYSTEM_ADDRESS)&x + 2, i, INTEGER);
_o_result = __MASK(__ASHR(i, 7), -256);
return _o_result;
}
void Reals_SetExpo (REAL *x, INTEGER ex)
{
CHAR c;
__GET((LONGINT)(SYSTEM_ADDRESS)x + 3, c, CHAR);
__PUT((LONGINT)(SYSTEM_ADDRESS)x + 3, (CHAR)(__ASHL(__ASHR((int)c, 7), 7) + __MASK(__ASHR(ex, 1), -128)), CHAR);
__GET((LONGINT)(SYSTEM_ADDRESS)x + 2, c, CHAR);
__PUT((LONGINT)(SYSTEM_ADDRESS)x + 2, (CHAR)(__MASK((int)c, -128) + __ASHL(__MASK(ex, -2), 7)), CHAR);
}
INTEGER Reals_ExpoL (LONGREAL x)
{
INTEGER _o_result;
INTEGER i;
__GET((LONGINT)(SYSTEM_ADDRESS)&x + 6, i, INTEGER);
_o_result = __MASK(__ASHR(i, 4), -2048);
return _o_result;
}
void Reals_ConvertL (LONGREAL x, INTEGER n, CHAR *d, LONGINT d__len)
{
LONGINT i, j, k;
if (x < (LONGREAL)0) {
x = -x;
}
k = 0;
i = __ENTIER(x);
while (k < (SYSTEM_INT64)n) {
d[__X(k, d__len)] = (CHAR)(__MOD(i, 10) + 48);
i = __DIV(i, 10);
k += 1;
}
}
void Reals_Convert (REAL x, INTEGER n, CHAR *d, LONGINT d__len)
{
Reals_ConvertL(x, n, (void*)d, d__len);
}
static CHAR Reals_ToHex (INTEGER i)
{
CHAR _o_result;
if (i < 10) {
_o_result = (CHAR)(i + 48);
return _o_result;
} else {
_o_result = (CHAR)(i + 55);
return _o_result;
}
__RETCHK;
}
static void Reals_BytesToHex (SYSTEM_BYTE *b, LONGINT b__len, SYSTEM_BYTE *d, LONGINT d__len)
{
INTEGER i;
LONGINT l;
CHAR by;
i = 0;
l = b__len;
while ((SYSTEM_INT64)i < l) {
by = __VAL(CHAR, b[__X(i, b__len)]);
d[__X(__ASHL(i, 1), d__len)] = Reals_ToHex(__ASHR((int)by, 4));
d[__X(__ASHL(i, 1) + 1, d__len)] = Reals_ToHex(__MASK((int)by, -16));
i += 1;
}
}
void Reals_ConvertH (REAL y, CHAR *d, LONGINT d__len)
{
Reals_BytesToHex((void*)&y, ((LONGINT)(4)), (void*)d, d__len * ((LONGINT)(1)));
}
void Reals_ConvertHL (LONGREAL x, CHAR *d, LONGINT d__len)
{
Reals_BytesToHex((void*)&x, ((LONGINT)(8)), (void*)d, d__len * ((LONGINT)(1)));
}
export void *Reals__init(void)
{
__DEFMOD;
__REGMOD("Reals", 0);
/* BEGIN */
__ENDMOD;
}