Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Approximate-equality/XPL0/approximate-equality.xpl0
Normal file
25
Task/Approximate-equality/XPL0/approximate-equality.xpl0
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
func ApproxEqual(A, B); \Return 'true' if approximately equal
|
||||
real A, B;
|
||||
real Epsilon;
|
||||
[Epsilon:= abs(A) * 1E-15;
|
||||
return abs(A-B) < Epsilon;
|
||||
];
|
||||
|
||||
real Data;
|
||||
int I;
|
||||
[Format(0, 16);
|
||||
Data:=[ [100000000000000.01, 100000000000000.011], \should return true
|
||||
[100.01, 100.011], \should return false
|
||||
[10000000000000.001 / 10000.0, 1000000000.0000001000],
|
||||
[0.001, 0.0010000001],
|
||||
[0.000000000000000000000101, 0.0], \is undefined
|
||||
[sqrt(2.0) * sqrt(2.0), 2.0],
|
||||
[-1.0 * sqrt(2.0) * sqrt(2.0), -2.0], \-sqrt doesn't compile!
|
||||
[3.14159265358979323846, 3.14159265358979324] ];
|
||||
for I:= 0 to 7 do
|
||||
[IntOut(0, I+1); Text(0, ". ");
|
||||
RlOut(0, Data(I,0)); ChOut(0, ^ ); RlOut(0, Data(I,1));
|
||||
Text(0, if ApproxEqual(Data(I,0), Data(I,1)) then " true" else " false");
|
||||
CrLf(0);
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue