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

@@ -84,7 +84,8 @@ lincat
Num = {s : Str ; sp : RCase => Str ; n : Number ; isNum : Bool} ;
Card = {s : Str ; sp : RCase => Str ; n : Number} ;
Numeral = {s : CardOrd => Str; n : Number} ;
Digits = {s : CardOrd => Str ; n : Number} ;
Digits = {s : CardOrd => Str ; n : Number} ;
Decimal = {s : CardOrd => Str ; n : Number; hasDot : Bool} ;
-- Structural

View File

@@ -109,7 +109,7 @@ lin
NumCard n = n ** {isNum = True} ;
NumDigits,NumNumeral = \numeral -> {
NumDigits,NumNumeral,NumDecimal = \numeral -> {
s = numeral.s ! NCard ;
sp = \\_ => numeral.s ! NCard ;
n = numeral.n

View File

@@ -1,6 +1,6 @@
--# -path=.:../abstract:../common:../prelude
concrete NumeralMon of Numeral = CatMon [Numeral,Digits] ** open ResMon, MorphoMon, Prelude in {
concrete NumeralMon of Numeral = CatMon [Numeral,Digits,Decimal] ** open ResMon, MorphoMon, Prelude in {
flags coding=utf8 ;
@@ -158,6 +158,20 @@ lin
D_8 = mkDig "8" ;
D_9 = mkDig "9" ;
PosDecimal d = d ** {hasDot=False} ;
NegDecimal d = {
s = \\co => "-" ++ BIND ++ d.s ! co ;
n = Pl ;
hasDot=False
} ;
IFrac d i = {
s = \\co => d.s ! NCard ++
if_then_Str d.hasDot BIND (BIND++"."++BIND) ++
i.s ! co;
n = Pl ;
hasDot=True
} ;
oper
mk2Dig : Str -> Str -> TDigit = \c,o -> mk3Dig c o Pl ;
mkDig : Str -> TDigit = \c -> mk2Dig c (c + "-р") ;