The new Decimal API

This commit is contained in:
Krasimir Angelov
2023-08-21 20:14:26 +02:00
parent 58da8deca8
commit fb398c603e
147 changed files with 918 additions and 188 deletions

View File

@@ -98,6 +98,11 @@ concrete CatMlt of Cat = CommonX - [Adv] ** open ResMlt, Prelude in {
n : NumForm ;
tail : DTail ;
} ;
Decimal = {
s : NumCase => Str ; -- No need for CardOrd, i.e. no 1st, 2nd etc in Maltese
n : NumForm ;
hasDot : Bool ;
} ;
-- Structural

View File

@@ -189,9 +189,7 @@ concrete NounMlt of Noun = CatMlt ** open ResMlt, Prelude, Maybe in {
-- 51
NumDigits d = {s = d.s ; n = d.n} ;
-- Digits -> Digits -> Card
-- 3.14
NumFloat d1 d2 = {s = \\c => d1.s ! NumNom ++ BIND ++ "." ++ BIND ++ d2.s ! c ; n = d1.n} ;
NumDecimal d = {s = d.s ; n = d.n} ;
-- Digits -> Ord
-- 51st

View File

@@ -4,7 +4,7 @@
-- John J. Camilleri 2011 -- 2013
-- Licensed under LGPL
concrete NumeralMlt of Numeral = CatMlt [Numeral,Digits] ** open Prelude,ResMlt in {
concrete NumeralMlt of Numeral = CatMlt [Numeral,Digits,Decimal] ** open Prelude,ResMlt in {
flags coding=utf8 ;
@@ -437,4 +437,18 @@ concrete NumeralMlt of Numeral = CatMlt [Numeral,Digits] ** open Prelude,ResMlt
tail = inc i.tail
} ;
PosDecimal d = d ** {hasDot=False} ;
NegDecimal d = {
s = \\o => "-" ++ BIND ++ d.s ! o ;
n = d.n ;
hasDot=False
} ;
IFrac d i = {
s=\\o=>d.s ! NumNom ++
if_then_Str d.hasDot BIND (BIND++"."++BIND) ++
i.s ! o;
n = d.n;
hasDot=True
} ;
}