stillwater-sc / universal

Large collection of number systems providing custom arithmetic for mixed-precision algorithm development and optimization for AI, Machine Learning, Computer Vision, Signal Processing, CAE, EDA, control, optimization, estimation, and approximation.
MIT License
404 stars 59 forks source link

Implement specialized posit<16,2> sub, mul, div #404

Closed davidmallasen closed 9 months ago

davidmallasen commented 9 months ago

Following issue https://github.com/stillwater-sc/universal/issues/343 I implemented the specialized posit<16,2> sub, mul and div operations. Now addition, subtraction and multiplication are passing the exhaustive tests, but division is not working 100% and I can't seem to see why.

Ravenwater commented 9 months ago

Looks like we are not yet handling the geometric regimes correctly:

Manual exhaustive div
FAIL
8.5265128291212022305e-14 /                       128 != 2.2204460492503130808e-16 golden reference is 8.8817841970012523234e-16
    0b0.000000000001.00.1 /     0b0.110.11.0000000000 !=     0b0.00000000000001.0. golden reference is     0b0.00000000000001.1.
FAIL
8.5265128291212022305e-14 /                      -128 != -2.2204460492503130808e-16 golden reference is -8.8817841970012523234e-16
    0b0.000000000001.00.1 /     0b1.110.11.0000000000 !=     0b1.00000000000001.0. golden reference is     0b1.00000000000001.1.
FAIL
1.7053025658242404461e-13 /                       256 != 2.2204460492503130808e-16 golden reference is 8.8817841970012523234e-16
    0b0.000000000001.01.1 /     0b0.1110.00.000000000 !=     0b0.00000000000001.0. golden reference is     0b0.00000000000001.1.
FAIL
1.7053025658242404461e-13 /                      -256 != -2.2204460492503130808e-16 golden reference is -8.8817841970012523234e-16
    0b0.000000000001.01.1 /     0b1.1110.00.000000000 !=     0b1.00000000000001.0. golden reference is     0b1.00000000000001.1.
FAIL
3.4106051316484808922e-13 /                       512 != 2.2204460492503130808e-16 golden reference is 8.8817841970012523234e-16
    0b0.000000000001.10.1 /     0b0.1110.01.000000000 !=     0b0.00000000000001.0. golden reference is     0b0.00000000000001.1.
FAIL
3.4106051316484808922e-13 /                      -512 != -2.2204460492503130808e-16 golden reference is -8.8817841970012523234e-16
    0b0.000000000001.10.1 /     0b1.1110.01.000000000 !=     0b1.00000000000001.0. golden reference is     0b1.00000000000001.1.
FAIL
6.8212102632969617844e-13 /                      1024 != 2.2204460492503130808e-16 golden reference is 8.8817841970012523234e-16
    0b0.000000000001.11.1 /     0b0.1110.10.000000000 !=     0b0.00000000000001.0. golden reference is     0b0.00000000000001.1.

I'll try to RCA

Ravenwater commented 9 months ago

A small randomized subset loves you

Fast specialization posit<16,2>: report test cases
 posit< 16,2> useed scale     4     minpos scale        -56     maxpos scale         56  :  0

Special case tests
posit< 16, 2> Initialize to zero:            PASS
posit< 16, 2> Initialize to NAN              PASS
posit< 16, 2> Initialize to INFINITY         PASS
posit< 16, 2> sign is true                   PASS
posit< 16, 2> is negative                    PASS
posit< 16, 2> sign is false                  PASS
posit< 16, 2> is positive                    PASS
posit< 16, 2>                                                addition       PASS
posit< 16, 2>                                                subtraction    PASS
posit< 16, 2>                                                multiplication PASS
posit< 16, 2>                                                division       PASS
Fast specialization posit<16,2>: PASS
Ravenwater commented 9 months ago

And the exhaustive add does too

posit addition validation: results only
posit<8,0>                                                   addition PASS
posit<16,2>                                                  addition PASS
posit addition validation: PASS