[package] [Java implementation] [Execution output]


BigDecimals


import java.math.BigDecimal;

import church.lang.Array;

// bigDecimal(String: s) = BigDecimal.new(s);
bigDecimal(double: d) = BigDecimal.valueOf(d);

// Arithmetic identities / implementation

                                 stream << (BigDecimal: a) = stream << a.toString();

// Equality

                        (BigDecimal: a) == (BigDecimal: b) = a.equals(b);

// Ring

                                         additive_identity = BigDecimal.ZERO;

                         (BigDecimal: a) + (BigDecimal: b) = a.add(b);

                                          -(BigDecimal: a) = a.negate();

                                   multiplicative_identity = BigDecimal.ONE;

                         (BigDecimal: a) * (BigDecimal: b) = a.multiply(b);

                                (BigDecimal: a) ^ (int: n) = a.pow(n);

// Euclidean

                   divide(BigDecimal: a, BigDecimal: b, f) = {qNr = a.divideAndRemainder(b); f(qNr[0], qNr[1])};

                    quotient(BigDecimal: a, BigDecimal: b) = a.divide(b);

                         (BigDecimal: a) % (BigDecimal: b) = a.remainder(b);

// Ordering

                     compare(BigDecimal: a, BigDecimal: b) = {
                                                                 c = a.compareTo(b);
                                                                 if c < 0 then Ordering.LT else
                                                                 if c > 0 then Ordering.GT else
                                                                               Ordering.EQ;
                                                             };