TestSupport:
PROC = {
xd: DREAL ¬ 4.5;
yd: DREAL ¬ 6.7;
xr: REAL ¬ 4.5;
yr: REAL ¬ 6.7;
epsR: REAL ¬ 1.0;
epsD: DREAL ¬ 1.0;
DebugPutString["TestSupport\n"];
DebugPutString["Computing REAL eps ... "];
DO
next: REAL ¬ epsR*0.5;
IF next+1.0 = 1.0 THEN {epsPlusR ¬ 1.0+epsR; EXIT};
epsR ¬ next;
ENDLOOP;
DebugPutString["epsR = "];
PutDReal[epsR];
DebugPutChar['\n];
DebugPutString["Computing DREAL eps ... "];
DO
next: DREAL ¬ epsD*0.5;
IF next+1.0 = 1.0 THEN {epsPlusD ¬ 1.0+epsD; EXIT};
epsD ¬ next;
ENDLOOP;
DebugPutString["epsD = "];
PutDReal[epsD];
DebugPutChar['\n];
DebugPutString["Example[zero] = "];
{
d: DREAL = DRealSupport.Example[zero];
PutDReal[d];
IF DRealSupport.Classify[d] # zero THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["Example[subnormal, TRUE] = "];
{
d: DREAL = DRealSupport.Example[subnormal, TRUE];
PutDReal[d];
IF DRealSupport.Classify[d] # subnormal THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["Example[subnormal, FALSE] = "];
{
d: DREAL = DRealSupport.Example[subnormal, FALSE];
PutDReal[d];
IF DRealSupport.Classify[d] # subnormal THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["Example[normal, TRUE] = "];
{
d: DREAL = DRealSupport.Example[normal, TRUE];
PutDReal[d];
IF DRealSupport.Classify[d] # normal THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["Example[normal, FALSE] = "];
{
d: DREAL = DRealSupport.Example[normal, FALSE];
PutDReal[d];
IF DRealSupport.Classify[d] # normal THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["Example[infinity] = "];
{
d: DREAL = DRealSupport.Example[infinity];
PutDReal[d];
IF DRealSupport.Classify[d] # infinity THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["Example[quiet] = "];
{
d: DREAL = DRealSupport.Example[quiet];
PutDReal[d];
IF DRealSupport.Classify[d] # quiet THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["Example[signaling] = "];
{
d: DREAL = DRealSupport.Example[signaling];
PutDReal[d];
IF DRealSupport.Classify[d] # signaling THEN DebugPutString[" <<Bad classification>>"];
};
DebugPutChar['\n];
DebugPutString["xd = "];
PutDReal[xd];
DebugPutString[", yd = "];
PutDReal[yd];
DebugPutString[", xr = "];
PutDReal[xr];
DebugPutString[", yr = "];
PutDReal[yr];
DebugPutChar['\n];
TestMixed[xd+yd, xr+yr, "addition (DREAL vs. REAL)", epsPlusR];
TestMixed[xd-yd, xr-yr, "subtraction (DREAL vs. REAL)", epsPlusR];
TestMixed[xd*yd, xr*yr, "multiplication (DREAL vs. REAL)", epsPlusR];
TestMixed[xd/yd, xr/yr, "division (DREAL vs. REAL)", epsPlusR];
TestMixed[xd**yd, xr**yr, "power (DREAL vs. REAL)", epsPlusR**yr];
DebugPutString["\n"];
};
TestFns:
PROC = {
OPEN DRealFns;
DebugPutString["TestFns\n"];
TestDouble[Exp[Ln[4.7]], 4.7, "Exp[Ln[4.7]] = 4.7", epsPlusD];
TestDouble[Ln[Exp[4.7]], 4.7, "Ln[Exp[4.7]] = 4.7", epsPlusD];
TestDouble[SqRt[DREAL[4.7]*4.7], 4.7, "SqRt[4.7*4.7] = 4.7", SqRt[epsPlusD*epsPlusD]];
TestDouble[SqRt[0.0], 0.0, "SqRt[0.0] = 0.0", epsPlusD];
TestDouble[Sin[0.6]**2+Cos[0.6]**2, 1.0, "Sin[0.6]**2+Cos[0.6]**2 = 1.0", epsPlusD];
TestDouble[SinDeg[30.0], 0.5, "SinDeg[30.0] = 0.5", epsPlusD];
TestDouble[ArcTan[Tan[0.6], 1.0], 0.6, "ArcTan[Tan[0.6]] = 0.6", epsPlusD];
TestDouble[Gamma[4.0], 6.0, "Gamma[4.0] = 6.0", epsPlusD];
DebugPutString["\n"];
};
TestErrors:
PROC = {
OPEN DRealFns;
quietNaN: DREAL = DRealSupport.Example[quiet];
infinity: DREAL = DRealSupport.Example[infinity];
ec: FloatingPointCommon.Exception;
DebugPutString["TestErrors\n"];
IF setHardwareCheck
THEN {
[] ¬ FloatingPointPrivate.SetState[hardware];
IF FloatingPointPrivate.currentState # hardware
THEN
DebugPutString["(could not set hardware checking)\n"];
};
{
ENABLE FloatingPointCommon.Error => {ec ¬ code; GO TO done};
one: DREAL ¬ 1.0;
zero: DREAL ¬ 0.0;
div: DREAL ¬ one/zero;
PrintClass[DRealSupport.Classify[div], "1.0/0.0 has class of "];
DebugPutString["\n"];
TestDouble[div, infinity, "1.0/0.0 = infinity", epsPlusD];
EXITS done => PrintCode[ec, "1.0/0.0"];
};
{
ENABLE FloatingPointCommon.Error => {ec ¬ code; GO TO done};
TestDouble[SqRt[-1.0], quietNaN, "SqRt[-1.0] = quietNaN", epsPlusD];
EXITS done => PrintCode[ec, "SqRt[-1.0]"];
};
{
ENABLE FloatingPointCommon.Error => {ec ¬ code; GO TO done};
TestDouble[Ln[0.0], quietNaN, "Ln[0.0] = quietNaN", epsPlusD];
EXITS done => PrintCode[ec, "Ln[0.0]"];
};
{
ENABLE FloatingPointCommon.Error => {ec ¬ code; GO TO done};
TestDouble[Ln[-1.0], quietNaN, "Ln[-1.0] = quietNaN", epsPlusD];
EXITS done => PrintCode[ec, "Ln[-1.0]"];
};
DebugPutString["\n"];
};