sub bug?

Started by vashushpanov, January 11, 2024, 07:12:11 PM

Previous topic - Next topic

vashushpanov

> (sub 9999999999999999,0 9999999999999998,0)
=> 2
> (- 9999999999999999 9999999999999998)
=> 1

cameyo

#1
Some test:

(format "%.20f" (sub 9999999999999999 9999999999999998))
=> "2.00000000000000000000" (error)

(format "%.20f" (sub 999999999999999  999999999999998))
=> "1.00000000000000000000" (ok)

(format "%.20f" (sub 8888888888888889 8888888888888888))
=> "1.00000000000000000000" (ok)

(format "%.20f" (sub 1000000000000000 999999999999999))
=> "1.00000000000000000000" (ok)

(format "%.20f" (sub 10000000000000000 9999999999999999))
=> "0.00000000000000000000" (error)


(format "%.20f" (sub 10000000000000000 1))
=> "10000000000000000.00000000000000000000"

(format "%.20f" (sub 10000000000000000 2))
=> "9999999999999998.00000000000000000000"

(format "%.20f" (sub 10000000000000000 3))
=> "9999999999999996.00000000000000000000"

(format "%.20f" (sub 10000000000000000 4))
=> "9999999999999996.00000000000000000000"

(format "%.20f" (sub 10000000000000000 5))
=> "9999999999999996.00000000000000000000"

(format "%.20f" (sub 10000000000000000 6))
=> "9999999999999994.00000000000000000000"


In C++:
#include <iostream>

using namespace std;

int main()
{
    cout<<(1e16 - 1) << endl;
    cout<<(10000000000000000 - 1);
    return 0;
}
=> 1e+16
=> 9999999999999999

cameyo

From the newLISP manual:
QuotenewLISP has two types of basic arithmetic operators: integer (+ - * /) and floating point (add sub mul div).
The arithmetic functions convert their arguments into types compatible with the function's own type: integer function arguments into integers, floating point function arguments into floating points.