WeixiangYan/CodeTransOcean huggingface dataset:
Task: Approximate equality

C: #include <math.h>
#include <stdbool.h>
#include <stdio.h>

bool approxEquals(double value, double other, double epsilon) {
    return fabs(value - other) < epsilon;
}

void test(double a, double b) {
    double epsilon = 1e-18;
    printf("%f, %f => %d\n", a, b, approxEquals(a, b, epsilon));
}

int main() {
    test(100000000000000.01, 100000000000000.011);
    test(100.01, 100.011);
    test(10000000000000.001 / 10000.0, 1000000000.0000001000);
    test(0.001, 0.0010000001);
    test(0.000000000000000000000101, 0.0);
    test(sqrt(2.0) * sqrt(2.0), 2.0);
    test(-sqrt(2.0) * sqrt(2.0), -2.0);
    test(3.14159265358979323846, 3.14159265358979324);
    return 0;
}





Java: public class Approximate {
    private static boolean approxEquals(double value, double other, double epsilon) {
        return Math.abs(value - other) < epsilon;
    }

    private static void test(double a, double b) {
        double epsilon = 1e-18;
        System.out.printf("%f, %f => %s\n", a, b, approxEquals(a, b, epsilon));
    }

    public static void main(String[] args) {
        test(100000000000000.01, 100000000000000.011);
        test(100.01, 100.011);
        test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        test(0.001, 0.0010000001);
        test(0.000000000000000000000101, 0.0);
        test(Math.sqrt(2.0) * Math.sqrt(2.0), 2.0);
        test(-Math.sqrt(2.0) * Math.sqrt(2.0), -2.0);
        test(3.14159265358979323846, 3.14159265358979324);
    }
}
Task: Approximate equality

C: #include <math.h>
#include <stdbool.h>
#include <stdio.h>

bool approxEquals(double value, double other, double epsilon) {
    return fabs(value - other) < epsilon;
}

void test(double a, double b) {
    double epsilon = 1e-18;
    printf("%f, %f => %d\n", a, b, approxEquals(a, b, epsilon));
}

int main() {
    test(100000000000000.01, 100000000000000.011);
    test(100.01, 100.011);
    test(10000000000000.001 / 10000.0, 1000000000.0000001000);
    test(0.001, 0.0010000001);
    test(0.000000000000000000000101, 0.0);
    test(sqrt(2.0) * sqrt(2.0), 2.0);
    test(-sqrt(2.0) * sqrt(2.0), -2.0);
    test(3.14159265358979323846, 3.14159265358979324);
    return 0;
}







Python: from numpy import sqrt
from math import isclose

testvalues = [[100000000000000.01,           100000000000000.011],
              [100.01,                       100.011],
              [10000000000000.001 / 10000.0, 1000000000.0000001000],
              [0.001,                        0.0010000001],
              [0.000000000000000000000101,   0.0],
              [sqrt(2) * sqrt(2),            2.0],
              [-sqrt(2) * sqrt(2),          -2.0],
              [3.14159265358979323846,       3.14159265358979324]]

for (x, y) in testvalues:
    maybenot = "is" if isclose(x, y) else "is NOT"
    print(x, maybenot, "approximately equal to ", y)
Task: Approximate equality

C: #include <math.h>
#include <stdbool.h>
#include <stdio.h>

bool approxEquals(double value, double other, double epsilon) {
    return fabs(value - other) < epsilon;
}

void test(double a, double b) {
    double epsilon = 1e-18;
    printf("%f, %f => %d\n", a, b, approxEquals(a, b, epsilon));
}

int main() {
    test(100000000000000.01, 100000000000000.011);
    test(100.01, 100.011);
    test(10000000000000.001 / 10000.0, 1000000000.0000001000);
    test(0.001, 0.0010000001);
    test(0.000000000000000000000101, 0.0);
    test(sqrt(2.0) * sqrt(2.0), 2.0);
    test(-sqrt(2.0) * sqrt(2.0), -2.0);
    test(3.14159265358979323846, 3.14159265358979324);
    return 0;
}








VB: Imports System.Runtime.CompilerServices

Module Module1

    <Extension()>
    Function ApproxEquals(ByVal value As Double, other As Double, epsilon As Double)
        Return Math.Abs(value - other) < epsilon
    End Function

    Sub Test(a As Double, b As Double)
        Dim epsilon = 1.0E-18
        Console.WriteLine($"{a}, {b} => {a.ApproxEquals(b, epsilon)}")
    End Sub

    Sub Main()
        Test(100000000000000.02, 100000000000000.02)
        Test(100.01, 100.011)
        Test(10000000000000.002 / 10000.0, 1000000000.0000001)
        Test(0.001, 0.0010000001)
        Test(1.01E-22, 0.0)
        Test(Math.Sqrt(2) * Math.Sqrt(2), 2.0)
        Test(-Math.Sqrt(2) * Math.Sqrt(2), -2.0)
        Test(3.1415926535897931, 3.1415926535897931)
    End Sub

End Module
Task: Approximate equality


C++: #include <iomanip>
#include <iostream>
#include <cmath>

bool approxEquals(double a, double b, double e) {
    return fabs(a - b) < e;
}

void test(double a, double b) {
    constexpr double epsilon = 1e-18;
    std::cout << std::setprecision(21) << a;
    std::cout << ", ";
    std::cout << std::setprecision(21) << b;
    std::cout << " => ";
    std::cout << approxEquals(a, b, epsilon) << '\n';
}

int main() {
    test(100000000000000.01, 100000000000000.011);
    test(100.01, 100.011);
    test(10000000000000.001 / 10000.0, 1000000000.0000001000);
    test(0.001, 0.0010000001);
    test(0.000000000000000000000101, 0.0);
    test(sqrt(2.0) * sqrt(2.0), 2.0);
    test(-sqrt(2.0) * sqrt(2.0), -2.0);
    test(3.14159265358979323846, 3.14159265358979324);
    return 0;
}


C#: using System;

public static class Program
{
    public static void Main() {
        Test(100000000000000.01, 100000000000000.011);
        Test(100.01, 100.011);
        Test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        Test(0.001, 0.0010000001);
        Test(0.000000000000000000000101, 0.0);
        Test(Math.Sqrt(2) * Math.Sqrt(2), 2.0);
        Test(-Math.Sqrt(2) * Math.Sqrt(2), -2.0);
        Test(3.14159265358979323846, 3.14159265358979324);

        void Test(double a, double b) {
            const double epsilon = 1e-18;
            WriteLine($"{a}, {b} => {a.ApproxEquals(b, epsilon)}");
        }
    }

    public static bool ApproxEquals(this double value, double other, double epsilon) => Math.Abs(value - other) < epsilon;
}
Task: Approximate equality


C++: #include <iomanip>
#include <iostream>
#include <cmath>

bool approxEquals(double a, double b, double e) {
    return fabs(a - b) < e;
}

void test(double a, double b) {
    constexpr double epsilon = 1e-18;
    std::cout << std::setprecision(21) << a;
    std::cout << ", ";
    std::cout << std::setprecision(21) << b;
    std::cout << " => ";
    std::cout << approxEquals(a, b, epsilon) << '\n';
}

int main() {
    test(100000000000000.01, 100000000000000.011);
    test(100.01, 100.011);
    test(10000000000000.001 / 10000.0, 1000000000.0000001000);
    test(0.001, 0.0010000001);
    test(0.000000000000000000000101, 0.0);
    test(sqrt(2.0) * sqrt(2.0), 2.0);
    test(-sqrt(2.0) * sqrt(2.0), -2.0);
    test(3.14159265358979323846, 3.14159265358979324);
    return 0;
}




Java: public class Approximate {
    private static boolean approxEquals(double value, double other, double epsilon) {
        return Math.abs(value - other) < epsilon;
    }

    private static void test(double a, double b) {
        double epsilon = 1e-18;
        System.out.printf("%f, %f => %s\n", a, b, approxEquals(a, b, epsilon));
    }

    public static void main(String[] args) {
        test(100000000000000.01, 100000000000000.011);
        test(100.01, 100.011);
        test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        test(0.001, 0.0010000001);
        test(0.000000000000000000000101, 0.0);
        test(Math.sqrt(2.0) * Math.sqrt(2.0), 2.0);
        test(-Math.sqrt(2.0) * Math.sqrt(2.0), -2.0);
        test(3.14159265358979323846, 3.14159265358979324);
    }
}
Task: Approximate equality


C++: #include <iomanip>
#include <iostream>
#include <cmath>

bool approxEquals(double a, double b, double e) {
    return fabs(a - b) < e;
}

void test(double a, double b) {
    constexpr double epsilon = 1e-18;
    std::cout << std::setprecision(21) << a;
    std::cout << ", ";
    std::cout << std::setprecision(21) << b;
    std::cout << " => ";
    std::cout << approxEquals(a, b, epsilon) << '\n';
}

int main() {
    test(100000000000000.01, 100000000000000.011);
    test(100.01, 100.011);
    test(10000000000000.001 / 10000.0, 1000000000.0000001000);
    test(0.001, 0.0010000001);
    test(0.000000000000000000000101, 0.0);
    test(sqrt(2.0) * sqrt(2.0), 2.0);
    test(-sqrt(2.0) * sqrt(2.0), -2.0);
    test(3.14159265358979323846, 3.14159265358979324);
    return 0;
}






Python: from numpy import sqrt
from math import isclose

testvalues = [[100000000000000.01,           100000000000000.011],
              [100.01,                       100.011],
              [10000000000000.001 / 10000.0, 1000000000.0000001000],
              [0.001,                        0.0010000001],
              [0.000000000000000000000101,   0.0],
              [sqrt(2) * sqrt(2),            2.0],
              [-sqrt(2) * sqrt(2),          -2.0],
              [3.14159265358979323846,       3.14159265358979324]]

for (x, y) in testvalues:
    maybenot = "is" if isclose(x, y) else "is NOT"
    print(x, maybenot, "approximately equal to ", y)
Task: Approximate equality


C++: #include <iomanip>
#include <iostream>
#include <cmath>

bool approxEquals(double a, double b, double e) {
    return fabs(a - b) < e;
}

void test(double a, double b) {
    constexpr double epsilon = 1e-18;
    std::cout << std::setprecision(21) << a;
    std::cout << ", ";
    std::cout << std::setprecision(21) << b;
    std::cout << " => ";
    std::cout << approxEquals(a, b, epsilon) << '\n';
}

int main() {
    test(100000000000000.01, 100000000000000.011);
    test(100.01, 100.011);
    test(10000000000000.001 / 10000.0, 1000000000.0000001000);
    test(0.001, 0.0010000001);
    test(0.000000000000000000000101, 0.0);
    test(sqrt(2.0) * sqrt(2.0), 2.0);
    test(-sqrt(2.0) * sqrt(2.0), -2.0);
    test(3.14159265358979323846, 3.14159265358979324);
    return 0;
}







VB: Imports System.Runtime.CompilerServices

Module Module1

    <Extension()>
    Function ApproxEquals(ByVal value As Double, other As Double, epsilon As Double)
        Return Math.Abs(value - other) < epsilon
    End Function

    Sub Test(a As Double, b As Double)
        Dim epsilon = 1.0E-18
        Console.WriteLine($"{a}, {b} => {a.ApproxEquals(b, epsilon)}")
    End Sub

    Sub Main()
        Test(100000000000000.02, 100000000000000.02)
        Test(100.01, 100.011)
        Test(10000000000000.002 / 10000.0, 1000000000.0000001)
        Test(0.001, 0.0010000001)
        Test(1.01E-22, 0.0)
        Test(Math.Sqrt(2) * Math.Sqrt(2), 2.0)
        Test(-Math.Sqrt(2) * Math.Sqrt(2), -2.0)
        Test(3.1415926535897931, 3.1415926535897931)
    End Sub

End Module
Task: Approximate equality



C#: using System;

public static class Program
{
    public static void Main() {
        Test(100000000000000.01, 100000000000000.011);
        Test(100.01, 100.011);
        Test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        Test(0.001, 0.0010000001);
        Test(0.000000000000000000000101, 0.0);
        Test(Math.Sqrt(2) * Math.Sqrt(2), 2.0);
        Test(-Math.Sqrt(2) * Math.Sqrt(2), -2.0);
        Test(3.14159265358979323846, 3.14159265358979324);

        void Test(double a, double b) {
            const double epsilon = 1e-18;
            WriteLine($"{a}, {b} => {a.ApproxEquals(b, epsilon)}");
        }
    }

    public static bool ApproxEquals(this double value, double other, double epsilon) => Math.Abs(value - other) < epsilon;
}


Go: package main

import (
    "fmt"
    "log"
    "math/big"
)

func max(a, b *big.Float) *big.Float {
    if a.Cmp(b) > 0 {
        return a
    }
    return b
}

func isClose(a, b *big.Float) bool {
    relTol := big.NewFloat(1e-9) 
    t := new(big.Float)
    t.Sub(a, b)
    t.Abs(t)
    u, v, w := new(big.Float), new(big.Float), new(big.Float)
    u.Mul(relTol, max(v.Abs(a), w.Abs(b)))
    return t.Cmp(u) <= 0
}

func nbf(s string) *big.Float {
    n, ok := new(big.Float).SetString(s)
    if !ok {
        log.Fatal("invalid floating point number")
    }
    return n
}

func main() {
    root2 := big.NewFloat(2.0)
    root2.Sqrt(root2)
    pairs := [][2]*big.Float{
        {nbf("100000000000000.01"), nbf("100000000000000.011")},
        {nbf("100.01"), nbf("100.011")},
        {nbf("0").Quo(nbf("10000000000000.001"), nbf("10000.0")), nbf("1000000000.0000001000")},
        {nbf("0.001"), nbf("0.0010000001")},
        {nbf("0.000000000000000000000101"), nbf("0.0")},
        {nbf("0").Mul(root2, root2), nbf("2.0")},
        {nbf("0").Mul(nbf("0").Neg(root2), root2), nbf("-2.0")},
        {nbf("100000000000000003.0"), nbf("100000000000000004.0")},
        {nbf("3.14159265358979323846"), nbf("3.14159265358979324")},
    }
    for _, pair := range pairs {
        s := "≉"
        if isClose(pair[0], pair[1]) {
            s = "≈"
        }
        fmt.Printf("% 21.19g %s %- 21.19g\n", pair[0], s, pair[1])
    }
}
Task: Approximate equality



C#: using System;

public static class Program
{
    public static void Main() {
        Test(100000000000000.01, 100000000000000.011);
        Test(100.01, 100.011);
        Test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        Test(0.001, 0.0010000001);
        Test(0.000000000000000000000101, 0.0);
        Test(Math.Sqrt(2) * Math.Sqrt(2), 2.0);
        Test(-Math.Sqrt(2) * Math.Sqrt(2), -2.0);
        Test(3.14159265358979323846, 3.14159265358979324);

        void Test(double a, double b) {
            const double epsilon = 1e-18;
            WriteLine($"{a}, {b} => {a.ApproxEquals(b, epsilon)}");
        }
    }

    public static bool ApproxEquals(this double value, double other, double epsilon) => Math.Abs(value - other) < epsilon;
}





Python: from numpy import sqrt
from math import isclose

testvalues = [[100000000000000.01,           100000000000000.011],
              [100.01,                       100.011],
              [10000000000000.001 / 10000.0, 1000000000.0000001000],
              [0.001,                        0.0010000001],
              [0.000000000000000000000101,   0.0],
              [sqrt(2) * sqrt(2),            2.0],
              [-sqrt(2) * sqrt(2),          -2.0],
              [3.14159265358979323846,       3.14159265358979324]]

for (x, y) in testvalues:
    maybenot = "is" if isclose(x, y) else "is NOT"
    print(x, maybenot, "approximately equal to ", y)
Task: Approximate equality




Go: package main

import (
    "fmt"
    "log"
    "math/big"
)

func max(a, b *big.Float) *big.Float {
    if a.Cmp(b) > 0 {
        return a
    }
    return b
}

func isClose(a, b *big.Float) bool {
    relTol := big.NewFloat(1e-9) 
    t := new(big.Float)
    t.Sub(a, b)
    t.Abs(t)
    u, v, w := new(big.Float), new(big.Float), new(big.Float)
    u.Mul(relTol, max(v.Abs(a), w.Abs(b)))
    return t.Cmp(u) <= 0
}

func nbf(s string) *big.Float {
    n, ok := new(big.Float).SetString(s)
    if !ok {
        log.Fatal("invalid floating point number")
    }
    return n
}

func main() {
    root2 := big.NewFloat(2.0)
    root2.Sqrt(root2)
    pairs := [][2]*big.Float{
        {nbf("100000000000000.01"), nbf("100000000000000.011")},
        {nbf("100.01"), nbf("100.011")},
        {nbf("0").Quo(nbf("10000000000000.001"), nbf("10000.0")), nbf("1000000000.0000001000")},
        {nbf("0.001"), nbf("0.0010000001")},
        {nbf("0.000000000000000000000101"), nbf("0.0")},
        {nbf("0").Mul(root2, root2), nbf("2.0")},
        {nbf("0").Mul(nbf("0").Neg(root2), root2), nbf("-2.0")},
        {nbf("100000000000000003.0"), nbf("100000000000000004.0")},
        {nbf("3.14159265358979323846"), nbf("3.14159265358979324")},
    }
    for _, pair := range pairs {
        s := "≉"
        if isClose(pair[0], pair[1]) {
            s = "≈"
        }
        fmt.Printf("% 21.19g %s %- 21.19g\n", pair[0], s, pair[1])
    }
}


Java: public class Approximate {
    private static boolean approxEquals(double value, double other, double epsilon) {
        return Math.abs(value - other) < epsilon;
    }

    private static void test(double a, double b) {
        double epsilon = 1e-18;
        System.out.printf("%f, %f => %s\n", a, b, approxEquals(a, b, epsilon));
    }

    public static void main(String[] args) {
        test(100000000000000.01, 100000000000000.011);
        test(100.01, 100.011);
        test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        test(0.001, 0.0010000001);
        test(0.000000000000000000000101, 0.0);
        test(Math.sqrt(2.0) * Math.sqrt(2.0), 2.0);
        test(-Math.sqrt(2.0) * Math.sqrt(2.0), -2.0);
        test(3.14159265358979323846, 3.14159265358979324);
    }
}
Task: Approximate equality





Java: public class Approximate {
    private static boolean approxEquals(double value, double other, double epsilon) {
        return Math.abs(value - other) < epsilon;
    }

    private static void test(double a, double b) {
        double epsilon = 1e-18;
        System.out.printf("%f, %f => %s\n", a, b, approxEquals(a, b, epsilon));
    }

    public static void main(String[] args) {
        test(100000000000000.01, 100000000000000.011);
        test(100.01, 100.011);
        test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        test(0.001, 0.0010000001);
        test(0.000000000000000000000101, 0.0);
        test(Math.sqrt(2.0) * Math.sqrt(2.0), 2.0);
        test(-Math.sqrt(2.0) * Math.sqrt(2.0), -2.0);
        test(3.14159265358979323846, 3.14159265358979324);
    }
}



Python: from numpy import sqrt
from math import isclose

testvalues = [[100000000000000.01,           100000000000000.011],
              [100.01,                       100.011],
              [10000000000000.001 / 10000.0, 1000000000.0000001000],
              [0.001,                        0.0010000001],
              [0.000000000000000000000101,   0.0],
              [sqrt(2) * sqrt(2),            2.0],
              [-sqrt(2) * sqrt(2),          -2.0],
              [3.14159265358979323846,       3.14159265358979324]]

for (x, y) in testvalues:
    maybenot = "is" if isclose(x, y) else "is NOT"
    print(x, maybenot, "approximately equal to ", y)
Task: Approximate equality





Java: public class Approximate {
    private static boolean approxEquals(double value, double other, double epsilon) {
        return Math.abs(value - other) < epsilon;
    }

    private static void test(double a, double b) {
        double epsilon = 1e-18;
        System.out.printf("%f, %f => %s\n", a, b, approxEquals(a, b, epsilon));
    }

    public static void main(String[] args) {
        test(100000000000000.01, 100000000000000.011);
        test(100.01, 100.011);
        test(10000000000000.001 / 10000.0, 1000000000.0000001000);
        test(0.001, 0.0010000001);
        test(0.000000000000000000000101, 0.0);
        test(Math.sqrt(2.0) * Math.sqrt(2.0), 2.0);
        test(-Math.sqrt(2.0) * Math.sqrt(2.0), -2.0);
        test(3.14159265358979323846, 3.14159265358979324);
    }
}




VB: Imports System.Runtime.CompilerServices

Module Module1

    <Extension()>
    Function ApproxEquals(ByVal value As Double, other As Double, epsilon As Double)
        Return Math.Abs(value - other) < epsilon
    End Function

    Sub Test(a As Double, b As Double)
        Dim epsilon = 1.0E-18
        Console.WriteLine($"{a}, {b} => {a.ApproxEquals(b, epsilon)}")
    End Sub

    Sub Main()
        Test(100000000000000.02, 100000000000000.02)
        Test(100.01, 100.011)
        Test(10000000000000.002 / 10000.0, 1000000000.0000001)
        Test(0.001, 0.0010000001)
        Test(1.01E-22, 0.0)
        Test(Math.Sqrt(2) * Math.Sqrt(2), 2.0)
        Test(-Math.Sqrt(2) * Math.Sqrt(2), -2.0)
        Test(3.1415926535897931, 3.1415926535897931)
    End Sub

End Module
Task: Approximate equality




Go: package main

import (
    "fmt"
    "log"
    "math/big"
)

func max(a, b *big.Float) *big.Float {
    if a.Cmp(b) > 0 {
        return a
    }
    return b
}

func isClose(a, b *big.Float) bool {
    relTol := big.NewFloat(1e-9) 
    t := new(big.Float)
    t.Sub(a, b)
    t.Abs(t)
    u, v, w := new(big.Float), new(big.Float), new(big.Float)
    u.Mul(relTol, max(v.Abs(a), w.Abs(b)))
    return t.Cmp(u) <= 0
}

func nbf(s string) *big.Float {
    n, ok := new(big.Float).SetString(s)
    if !ok {
        log.Fatal("invalid floating point number")
    }
    return n
}

func main() {
    root2 := big.NewFloat(2.0)
    root2.Sqrt(root2)
    pairs := [][2]*big.Float{
        {nbf("100000000000000.01"), nbf("100000000000000.011")},
        {nbf("100.01"), nbf("100.011")},
        {nbf("0").Quo(nbf("10000000000000.001"), nbf("10000.0")), nbf("1000000000.0000001000")},
        {nbf("0.001"), nbf("0.0010000001")},
        {nbf("0.000000000000000000000101"), nbf("0.0")},
        {nbf("0").Mul(root2, root2), nbf("2.0")},
        {nbf("0").Mul(nbf("0").Neg(root2), root2), nbf("-2.0")},
        {nbf("100000000000000003.0"), nbf("100000000000000004.0")},
        {nbf("3.14159265358979323846"), nbf("3.14159265358979324")},
    }
    for _, pair := range pairs {
        s := "≉"
        if isClose(pair[0], pair[1]) {
            s = "≈"
        }
        fmt.Printf("% 21.19g %s %- 21.19g\n", pair[0], s, pair[1])
    }
}




Python: from numpy import sqrt
from math import isclose

testvalues = [[100000000000000.01,           100000000000000.011],
              [100.01,                       100.011],
              [10000000000000.001 / 10000.0, 1000000000.0000001000],
              [0.001,                        0.0010000001],
              [0.000000000000000000000101,   0.0],
              [sqrt(2) * sqrt(2),            2.0],
              [-sqrt(2) * sqrt(2),          -2.0],
              [3.14159265358979323846,       3.14159265358979324]]

for (x, y) in testvalues:
    maybenot = "is" if isclose(x, y) else "is NOT"
    print(x, maybenot, "approximately equal to ", y)
Task: Approximate equality




Go: package main

import (
    "fmt"
    "log"
    "math/big"
)

func max(a, b *big.Float) *big.Float {
    if a.Cmp(b) > 0 {
        return a
    }
    return b
}

func isClose(a, b *big.Float) bool {
    relTol := big.NewFloat(1e-9) 
    t := new(big.Float)
    t.Sub(a, b)
    t.Abs(t)
    u, v, w := new(big.Float), new(big.Float), new(big.Float)
    u.Mul(relTol, max(v.Abs(a), w.Abs(b)))
    return t.Cmp(u) <= 0
}

func nbf(s string) *big.Float {
    n, ok := new(big.Float).SetString(s)
    if !ok {
        log.Fatal("invalid floating point number")
    }
    return n
}

func main() {
    root2 := big.NewFloat(2.0)
    root2.Sqrt(root2)
    pairs := [][2]*big.Float{
        {nbf("100000000000000.01"), nbf("100000000000000.011")},
        {nbf("100.01"), nbf("100.011")},
        {nbf("0").Quo(nbf("10000000000000.001"), nbf("10000.0")), nbf("1000000000.0000001000")},
        {nbf("0.001"), nbf("0.0010000001")},
        {nbf("0.000000000000000000000101"), nbf("0.0")},
        {nbf("0").Mul(root2, root2), nbf("2.0")},
        {nbf("0").Mul(nbf("0").Neg(root2), root2), nbf("-2.0")},
        {nbf("100000000000000003.0"), nbf("100000000000000004.0")},
        {nbf("3.14159265358979323846"), nbf("3.14159265358979324")},
    }
    for _, pair := range pairs {
        s := "≉"
        if isClose(pair[0], pair[1]) {
            s = "≈"
        }
        fmt.Printf("% 21.19g %s %- 21.19g\n", pair[0], s, pair[1])
    }
}





VB: Imports System.Runtime.CompilerServices

Module Module1

    <Extension()>
    Function ApproxEquals(ByVal value As Double, other As Double, epsilon As Double)
        Return Math.Abs(value - other) < epsilon
    End Function

    Sub Test(a As Double, b As Double)
        Dim epsilon = 1.0E-18
        Console.WriteLine($"{a}, {b} => {a.ApproxEquals(b, epsilon)}")
    End Sub

    Sub Main()
        Test(100000000000000.02, 100000000000000.02)
        Test(100.01, 100.011)
        Test(10000000000000.002 / 10000.0, 1000000000.0000001)
        Test(0.001, 0.0010000001)
        Test(1.01E-22, 0.0)
        Test(Math.Sqrt(2) * Math.Sqrt(2), 2.0)
        Test(-Math.Sqrt(2) * Math.Sqrt(2), -2.0)
        Test(3.1415926535897931, 3.1415926535897931)
    End Sub

End Module