예제 #1
0
def test_subF64_random():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    random.seed(a=None)  # uses current system time for seed

    test_vector = []

    for test in range(100):
        a = get_rand(-3000.0, 3000.0, 6)
        b = get_rand(-3000.0, 3000.0, 6)
        out = a - b

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([1, a, b, 0, out])

    run_tv_test(AddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
예제 #2
0
def test_hypothesis_subF64(a, b):

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.00000000001

    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #3
0
def test_subF32_random():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.001

    BN = mk_bits(expWidth + sigWidth)

    random.seed(precision)

    test_vector = []

    for test in range(100):
        a = get_rand(-1000.0, 1000.0, 4)
        b = get_rand(-1000.0, 1000.0, 4)
        out = a - b

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([1, a, b, 0, out])

    run_tv_test(AddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
예제 #4
0
def test_addF16_ones():

    expWidth = 5
    sigWidth = 11
    precision = expWidth + sigWidth
    tolerance = 0.001

    a = 1.0
    b = 1.0
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp a   b   roundingMode  out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #5
0
def test_subF64_positive_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = 1829.5982182
    b = -239484.000192
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #6
0
def test_subF64_negative_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = -58182.1913
    b = -1293.10092
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #7
0
def test_addF64_positive_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = 288.999102
    b = -12.59101
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #8
0
def test_addF64_negative_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = -192.491023
    b = -5.92929192931823
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #9
0
def test_addF64_positive_positive():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = 1829591.29201
    b = 58285.0291
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #10
0
def test_subF32_negative_negative():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.0001

    BN = mk_bits(expWidth + sigWidth)

    a = -692.21
    b = -12.49102
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #11
0
def test_addF32_negative_negative():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.0001

    BN = mk_bits(expWidth + sigWidth)

    a = -385.01
    b = -591.2021
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #12
0
def test_subF16_negative_negative():

    expWidth = 5
    sigWidth = 11
    precision = expWidth + sigWidth
    tolerance = 0.001

    BN = mk_bits(expWidth + sigWidth)

    a = -127.41
    b = -451.61
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
예제 #13
0
def test_subF16_positive_positive():

    expWidth = 5
    sigWidth = 11
    precision = expWidth + sigWidth
    tolerance = 0.001

    a = 17.61
    b = 231.41
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)