Correct handling of .Net deccimal type in Numbers operation

Description

A value of decimal type is often coerced improperly to Int64 before the numberic ops in Numbers are applied.
(> (decimal 1.1) (decimal 1.0)) => false INCORRECT
(<= (decimal 1.1) 1) => true INCORRECT
(< (decimal 1.0) (decimal 1.1)) => false INCORRECT
(<= (decimal 1.0) (decimal 1.1)) => true CORRECT
(<= (decimal 1.9) (decimal 1.1)) => true ;; Oh, no it does not work
(<= (decimal 2.0) (decimal 1.1)) => false ;; yes it works again if the value before the decimal point moves to the next value.

(def dbls '(1.0 1.1 1.2 2.0 2.1 2.2))
(def decis (map decimal dbls))
(map type decis) => (System.Decimal System.Decimal System.Decimal System.Decimal System.Decimal System.Decimal) – good
(map - decis) => (-1 -1 -1 -2 -2 -2) INCORRECT
(map #(* -1.0 %) decis) => (-1.0 -1.1 -1.2 -2.0 -2.1 -2.2) CORRECT
(map #(* (decimal -1.0) %) decis) => (-1 -1 -1 -2 -2 -2) INCORRECT
(map < decis (rest decis)) => (false false true false false) INCORRECT

Environment

None

Activity

Show:
David Miller
March 16, 2019, 9:09 PM

Went full bore and fixed support for decimal and unsigned types.
Had to modify the definition of intrinsic conversions for the numeric types to get this all to work.

David Miller
February 23, 2019, 8:37 PM

Fully fixing this problem is going to require a significant reworking of primitive numeric handling – putting that off for the ClojureCLR rewrite.
In the meantime, there are several aspects:
(1) Fix some odd problem with conversions, e.g. BigDecimal.ToDecimal.
(2) Work in clojure.lang.Numbers
(2a) Make sure there is an appropriate case for decimal in all operations.
(2a) Add a DecimalOps implementation to handle decimal/decimal operations.
(2c) Make sure the overload resolution code handles decimals
(3) Check to see if we can get Intrinsics to handle decimal and decimal-decimal intrinsic operations.

Same could be said for unsigned. Not sure if now is the time.

Completed

Assignee

David Miller

Reporter

David Miller