home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
icon
/
dos
/
src
/
tests
/
checkfpx.icn
< prev
next >
Wrap
Text File
|
1992-02-09
|
14KB
|
278 lines
procedure main()
write("This test of floating-point arithmetic is likely to show")
write("differences from platform to platform because of differences")
write("in floating-point precision and details of the routines that")
write("convert floating-point numbers to strings. If the values")
write("produced in local tests are approximately the same in magnitude")
write("as shown in the standard results, there's nothing to worry about.")
write("In addition, some platforms may show 0.0 as \"-0.0\". You can")
write("ignore this if you wish.")
p1()
p2()
p3()
p4()
p5()
p6()
end
procedure p1()
write("every 1 to 10 do write(?0) ----> ",(every 1 to 10 do write(Image(?0))) | "none")
write("every i := 1 to 50 do write(real(repl(\"0\",i) || \"2.\")) ----> ",Image(every i := 1 to 50 do write(real(repl("0",i) || "2."))) | "none")
write("every i := 1 to 30 do write(integer(repl(\"0\",i) || \"2\")) ----> ",Image(every i := 1 to 30 do write(integer(repl("0",i) || "2"))) | "none")
write("2.0 ~=== +2.0 ----> ",Image(2.0 ~=== +2.0) | "none")
write("abs(3.0) ----> ",Image(abs(3.0)) | "none")
write("Image(2e13) ----> ",Image(Image(2e13)) | "none")
write("Image(0.0006) ----> ",Image(Image(0.0006)) | "none")
write("Image(2.0) ----> ",Image(Image(2.0)) | "none")
write("integer(2.0) ----> ",Image(integer(2.0)) | "none")
write("integer(2.7) ----> ",Image(integer(2.7)) | "none")
write("integer(\".\") ----> ",Image(integer(".")) | "none")
write("integer(\".3\") ----> ",Image(integer(".3")) | "none")
write("integer(\"0.3\") ----> ",Image(integer("0.3")) | "none")
write("integer(\" . 3\") ----> ",Image(integer(" . 3")) | "none")
write("integer(\"e2\") ----> ",Image(integer("e2")) | "none")
write("integer(\"3e500\") ----> ",Image(integer("3e500")) | "none")
write("numeric(2.0) ----> ",Image(numeric(2.0)) | "none")
write("numeric(2.7) ----> ",Image(numeric(2.7)) | "none")
write("numeric(\".\") ----> ",Image(numeric(".")) | "none")
write("numeric(\".3\") ----> ",Image(numeric(".3")) | "none")
write("numeric(\"0.3\") ----> ",Image(numeric("0.3")) | "none")
end
procedure p2()
write("numeric(\" . 3\") ----> ",Image(numeric(" . 3")) | "none")
write("numeric(\"e2\") ----> ",Image(numeric("e2")) | "none")
write("numeric(\"3e500\") ----> ",Image(numeric("3e500")) | "none")
write("real(2) ----> ",Image(real(2)) | "none")
write("real(2.0) ----> ",Image(real(2.0)) | "none")
write("real(2.7) ----> ",Image(real(2.7)) | "none")
write("real(\"2\") ----> ",Image(real("2")) | "none")
write("real(\" 2\") ----> ",Image(real(" 2")) | "none")
write("real(\"2 \") ----> ",Image(real("2 ")) | "none")
write("real(\"+2\") ----> ",Image(real("+2")) | "none")
write("real(\"-2\") ----> ",Image(real("-2")) | "none")
write("real(\"- 2\") ----> ",Image(real("- 2")) | "none")
write("real(\" - 2 \") ----> ",Image(real(" - 2 ")) | "none")
write("real(\"\") ----> ",Image(real("")) | "none")
write("real(\"--2\") ----> ",Image(real("--2")) | "none")
write("real(\" \") ----> ",Image(real(" ")) | "none")
write("real(\"-\") ----> ",Image(real("-")) | "none")
write("real(\"+\") ----> ",Image(real("+")) | "none")
write("real(\".\") ----> ",Image(real(".")) | "none")
write("real(\".3\") ----> ",Image(real(".3")) | "none")
write("real(\"0.3\") ----> ",Image(real("0.3")) | "none")
write("real(\" . 3\") ----> ",Image(real(" . 3")) | "none")
write("real(\"e2\") ----> ",Image(real("e2")) | "none")
write("real(\"3e500\") ----> ",Image(real("3e500")) | "none")
write("real(\"7r4\") ----> ",Image(real("7r4")) | "none")
write("real(\"4r7\") ----> ",Image(real("4r7")) | "none")
write("real(\"4r 7\") ----> ",Image(real("4r 7")) | "none")
write("real(\"7r 4\") ----> ",Image(real("7r 4")) | "none")
write("real(\"16rff\") ----> ",Image(real("16rff")) | "none")
write("real(\"36rcat\") ----> ",Image(real("36rcat")) | "none")
write("real(\"36Rcat\") ----> ",Image(real("36Rcat")) | "none")
write("real(\"36rCAT\") ----> ",Image(real("36rCAT")) | "none")
write("real(\"1r1\") ----> ",Image(real("1r1")) | "none")
write("real(\"2r0\") ----> ",Image(real("2r0")) | "none")
write("real(\"22222222222222222222222222222\") ----> ",Image(real("22222222222222222222222222222")) | "none")
write("numeric(2.0) ----> ",Image(numeric(2.0)) | "none")
write("numeric(2.7) ----> ",Image(numeric(2.7)) | "none")
write("numeric(0.3) ----> ",Image(numeric(0.3)) | "none")
write("numeric(e2) ----> ",Image(numeric(e2)) | "none")
write("36. ^ 9 ----> ",Image(36. ^ 9) | "none")
write("36 ^ 9. ----> ",Image(36 ^ 9.) | "none")
write("36. ^ 9. ----> ",Image(36. ^ 9.) | "none")
write("-36. ^ 9 ----> ",Image(-36. ^ 9) | "none")
write("-36. ^ -9 ----> ",Image(-36. ^ -9) | "none")
write((every i := 1 to 37 do write(Image(real(repl("2",i) || ".")))) | "failed")
write((every i := 1 to 37 do write(Image(real(repl("2",i) || ".2")))) | "failed")
write((every i := 1 to 37 do write(Image((repl("2",i) || ".2") + 1))) | "failed")
write("2.0 === +2.0 ----> ",Image(2.0 === +2.0) | "none")
write("?30.0 ----> ",Image(?30.0) | "none")
end
procedure p3()
write("copy(1.0) ----> ",Image(copy(1.0)) | "none")
write("trim(3.14159,58) ----> ",Image(trim(3.14159,58)) | "none")
write("Image(2e13) ----> ",Image(Image(2e13)) | "none")
write("Image(0.0006) ----> ",Image(Image(0.0006)) | "none")
end
procedure p4()
write("Image(2.0) ----> ",Image(Image(2.0)) | "none")
write("string(2.0) ----> ",Image(string(2.0)) | "none")
write("string(2.7) ----> ",Image(string(2.7)) | "none")
write("string(\".\") ----> ",Image(string(".")) | "none")
write("string(\".3\") ----> ",Image(string(".3")) | "none")
write("string(\"0.3\") ----> ",Image(string("0.3")) | "none")
write("string(\" . 3\") ----> ",Image(string(" . 3")) | "none")
write("string(\"e2\") ----> ",Image(string("e2")) | "none")
write("string(\"3e500\") ----> ",Image(string("3e500")) | "none")
write("type(1.0) ----> ",Image(type(1.0)) | "none")
write("cset(2.0) ----> ",Image(cset(2.0)) | "none")
write("cset(2.7) ----> ",Image(cset(2.7)) | "none")
write("cset(\".\") ----> ",Image(cset(".")) | "none")
write("cset(\".3\") ----> ",Image(cset(".3")) | "none")
write("cset(\"0.3\") ----> ",Image(cset("0.3")) | "none")
write("cset(\" . 3\") ----> ",Image(cset(" . 3")) | "none")
write("cset(\"e2\") ----> ",Image(cset("e2")) | "none")
write("cset(\"3e500\") ----> ",Image(cset("3e500")) | "none")
write("+1.0 ----> ",Image(+1.0) | "none")
write("-1.0 ----> ",Image(-1.0) | "none")
end
procedure p5()
write("real(2) ----> ",Image(real(2)) | "none")
write("real(2.0) ----> ",Image(real(2.0)) | "none")
write("real(2.7) ----> ",Image(real(2.7)) | "none")
write("real(\"2\") ----> ",Image(real("2")) | "none")
write("real(\" 2\") ----> ",Image(real(" 2")) | "none")
write("real(\"2 \") ----> ",Image(real("2 ")) | "none")
write("real(\"+2\") ----> ",Image(real("+2")) | "none")
write("real(\"-2\") ----> ",Image(real("-2")) | "none")
write("real(\"- 2\") ----> ",Image(real("- 2")) | "none")
write("real(\" - 2 \") ----> ",Image(real(" - 2 ")) | "none")
write("real(\"\") ----> ",Image(real("")) | "none")
write("real(\"--2\") ----> ",Image(real("--2")) | "none")
write("real(\" \") ----> ",Image(real(" ")) | "none")
write("real(\"-\") ----> ",Image(real("-")) | "none")
write("real(\"+\") ----> ",Image(real("+")) | "none")
write("real(\".\") ----> ",Image(real(".")) | "none")
write("real(\".3\") ----> ",Image(real(".3")) | "none")
write("real(\"0.3\") ----> ",Image(real("0.3")) | "none")
write("real(\" . 3\") ----> ",Image(real(" . 3")) | "none")
write("real(\"e2\") ----> ",Image(real("e2")) | "none")
write("real(\"3e500\") ----> ",Image(real("3e500")) | "none")
write("real(\"7r4\") ----> ",Image(real("7r4")) | "none")
write("real(\"4r7\") ----> ",Image(real("4r7")) | "none")
write("real(\"4r 7\") ----> ",Image(real("4r 7")) | "none")
write("real(\"7r 4\") ----> ",Image(real("7r 4")) | "none")
write("real(\"16rff\") ----> ",Image(real("16rff")) | "none")
write("real(\"36rcat\") ----> ",Image(real("36rcat")) | "none")
write("real(\"36Rcat\") ----> ",Image(real("36Rcat")) | "none")
write("real(\"36rCAT\") ----> ",Image(real("36rCAT")) | "none")
write("real(\"1r1\") ----> ",Image(real("1r1")) | "none")
write("integer(2.0) ----> ",Image(integer(2.0)) | "none")
write("integer(2.7) ----> ",Image(integer(2.7)) | "none")
write("integer(\".\") ----> ",Image(integer(".")) | "none")
write("integer(\".3\") ----> ",Image(integer(".3")) | "none")
write("integer(\"0.3\") ----> ",Image(integer("0.3")) | "none")
write("integer(\" . 3\") ----> ",Image(integer(" . 3")) | "none")
write("numeric(2.0) ----> ",Image(numeric(2.0)) | "none")
write("numeric(2.7) ----> ",Image(numeric(2.7)) | "none")
write("numeric(\".\") ----> ",Image(numeric(".")) | "none")
write("numeric(\".3\") ----> ",Image(numeric(".3")) | "none")
write("numeric(\"0.3\") ----> ",Image(numeric("0.3")) | "none")
write("numeric(\" . 3\") ----> ",Image(numeric(" . 3")) | "none")
write("real(2.0) ----> ",Image(real(2.0)) | "none")
write("real(2.7) ----> ",Image(real(2.7)) | "none")
write("real(\".\") ----> ",Image(real(".")) | "none")
write("real(\".3\") ----> ",Image(real(".3")) | "none")
write("real(\"0.3\") ----> ",Image(real("0.3")) | "none")
write("real(\" . 3\") ----> ",Image(real(" . 3")) | "none")
write("abs(3.0) ----> ",Image(abs(3.0)) | "none")
write("abs(0.0) ----> ",Image(abs(0.0)) | "none")
write("abs(-3.0) ----> ",Image(abs(-3.0)) | "none")
write("36. % 7 ----> ",Image(36. % 7) | "none")
write("36 % 7. ----> ",Image(36 % 7.) | "none")
write("36. % 7. ----> ",Image(36. % 7.) | "none")
write("-36. % 7 ----> ",Image(-36. % 7) | "none")
write("36 % -7. ----> ",Image(36 % -7.) | "none")
write("-36. % -7. ----> ",Image(-36. % -7.) | "none")
write("36. * 9 ----> ",Image(36. * 9) | "none")
write("36 * 9. ----> ",Image(36 * 9.) | "none")
write("36. * 9. ----> ",Image(36. * 9.) | "none")
write("-36. * 9 ----> ",Image(-36. * 9) | "none")
end
procedure p6()
write("36 * -9. ----> ",Image(36 * -9.) | "none")
write("-36. * -9. ----> ",Image(-36. * -9.) | "none")
write("36. / 9 ----> ",Image(36. / 9) | "none")
write("36 / 9. ----> ",Image(36 / 9.) | "none")
write("36. / 9. ----> ",Image(36. / 9.) | "none")
write("-36. / 9 ----> ",Image(-36. / 9) | "none")
write("36 / -9. ----> ",Image(36 / -9.) | "none")
write("-36. / -9. ----> ",Image(-36. / -9.) | "none")
write("36. + 9 ----> ",Image(36. + 9) | "none")
write("36 + 9. ----> ",Image(36 + 9.) | "none")
write("36. + 9. ----> ",Image(36. + 9.) | "none")
write("-36. + 9 ----> ",Image(-36. + 9) | "none")
write("36 + -9. ----> ",Image(36 + -9.) | "none")
write("-36. + -9. ----> ",Image(-36. + -9.) | "none")
write("1. < 1 ----> ",Image(1. < 1) | "none")
write("1 < 2. ----> ",Image(1 < 2.) | "none")
write("1. < 0. ----> ",Image(1. < 0.) | "none")
write("-1 < 0. ----> ",Image(-1 < 0.) | "none")
write("1. < -2 ----> ",Image(1. < -2) | "none")
write("-1 < -0. ----> ",Image(-1 < -0.) | "none")
write("1. > 1 ----> ",Image(1. > 1) | "none")
write("1 > 2. ----> ",Image(1 > 2.) | "none")
write("1. > 0. ----> ",Image(1. > 0.) | "none")
write("-1 > 0. ----> ",Image(-1 > 0.) | "none")
write("1. > -2 ----> ",Image(1. > -2) | "none")
write("-1 > -0. ----> ",Image(-1 > -0.) | "none")
write("1. <= 1 ----> ",Image(1. <= 1) | "none")
write("1 <= 2. ----> ",Image(1 <= 2.) | "none")
write("1. <= 0. ----> ",Image(1. <= 0.) | "none")
write("-1 <= 0. ----> ",Image(-1 <= 0.) | "none")
write("1. <= -2 ----> ",Image(1. <= -2) | "none")
write("-1 <= -0. ----> ",Image(-1 <= -0.) | "none")
write("1. >= 1 ----> ",Image(1. >= 1) | "none")
write("1 >= 2. ----> ",Image(1 >= 2.) | "none")
write("1. >= 0. ----> ",Image(1. >= 0.) | "none")
write("-1 >= 0. ----> ",Image(-1 >= 0.) | "none")
write("1. >= -2 ----> ",Image(1. >= -2) | "none")
write("-1 >= -0. ----> ",Image(-1 >= -0.) | "none")
write("1. = 1 ----> ",Image(1. = 1) | "none")
write("1 = 2. ----> ",Image(1 = 2.) | "none")
write("1. = 0. ----> ",Image(1. = 0.) | "none")
write("-1 = 0. ----> ",Image(-1 = 0.) | "none")
write("1. = -2 ----> ",Image(1. = -2) | "none")
write("-1 = -0. ----> ",Image(-1 = -0.) | "none")
write("1. ~= 1 ----> ",Image(1. ~= 1) | "none")
write("1 ~= 2. ----> ",Image(1 ~= 2.) | "none")
write("1. ~= 0. ----> ",Image(1. ~= 0.) | "none")
write("-1 ~= 0. ----> ",Image(-1 ~= 0.) | "none")
write("1. ~= -2 ----> ",Image(1. ~= -2) | "none")
write("-1 ~= -0. ----> ",Image(-1 ~= -0.) | "none")
write("36. ^ 9 ----> ",Image(36. ^ 9) | "none")
write("36 ^ 9. ----> ",Image(36 ^ 9.) | "none")
write("36. ^ 9. ----> ",Image(36. ^ 9.) | "none")
write("-36. ^ 9 ----> ",Image(-36. ^ 9) | "none")
write("-36. ^ -9 ----> ",Image(-36. ^ -9) | "none")
write("end of checkfp")
end
procedure Image(x)
local head, tail, exp, span
span := 9
if type(x) ~== "real" then return image(x)
else {
x ? {
if head := tab(upto('e'))
then {
tail := tab(0)
head ? return (tab(span | 0) || tail)
}
else {
head := tab(span - 1 | 0)
#
# if head is too small to include the ".", go to floating point
# format.
#
if exp := *tab(upto('.')) then
head ? return move(1) || "." || move(span - 3) ||
"e+" || (span - 3 + exp)
else {
if head[-1] == "." then
head ||:= (move(1) | "0")
return head
}
}
}
}
end