22 lines
722 B
Text
22 lines
722 B
Text
import ballerina/io;
|
|
|
|
public function main() {
|
|
float[][] pairs = [
|
|
[100000000000000.01, 100000000000000.011],
|
|
[100.01, 100.011],
|
|
[10000000000000.001 / 10000.0, 1000000000.0000001000],
|
|
[0.001, 0.0010000001],
|
|
[0.000000000000000000000101, 0.0],
|
|
[2.0.sqrt() * 2.0.sqrt(), 2.0],
|
|
[-2.0.sqrt() * 2.0.sqrt(), -2.0],
|
|
[3.14159265358979323846, 3.14159265358979324]
|
|
];
|
|
io:println("Approximate equality of test cases with a tolerance of 1 bit:");
|
|
int i = 0;
|
|
foreach float[] pair in pairs {
|
|
i += 1;
|
|
int bi0 = pair[0].toBitsInt();
|
|
int bi1 = pair[1].toBitsInt();
|
|
io:println(` ${i} -> ${(bi0 - bi1).abs() <= 1}`);
|
|
}
|
|
}
|