Skip to content

Commit 8109831

Browse files
committed
fixed point nums wip
1 parent 3e4a72b commit 8109831

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

nix/configuration.nix

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -773,16 +773,6 @@ in {
773773
-file ./SimpleSlots.1.1.pk7
774774
'';
775775
}
776-
// fj.mkFirejailCustom {
777-
pkg = "doom-siren";
778-
dir = "doom";
779-
exe = ''
780-
${pkgs.gzdoom}/bin/gzdoom \
781-
-iwad ./freedoom-0.13.0/freedoom2.wad \
782-
-file ./siren.pk3 \
783-
-file ./SimpleSlots.1.1.pk7
784-
'';
785-
}
786776
// fj.mkFirejailCustom {
787777
pkg = "doom-ashes1";
788778
dir = "doom";

pub/functora/src/prelude/Functora/Prelude.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ module Functora.Prelude
122122

123123
-- * FixedPoint
124124
-- $fixedPoint
125+
E30,
125126
Fix (..),
126-
FixNonNeg,
127+
FixNonNeg (..),
127128
mkFixNonNeg,
128-
E30,
129+
inspectFixed,
129130

130131
-- * DerivingVia
131132
-- $derivingVia
@@ -1200,6 +1201,9 @@ mkFixNonNeg x =
12001201
then FixNonNeg x
12011202
else error $ "Underflow " <> inspect x
12021203

1204+
inspectFixed :: forall a e. (From String a, HasResolution e) => Fixed e -> a
1205+
inspectFixed = from @String @a . showFixed True
1206+
12031207
instance Num FixNonNeg where
12041208
lhs + rhs = mkFixNonNeg $ unFixNonNeg lhs + unFixNonNeg rhs
12051209
lhs - rhs = mkFixNonNeg $ unFixNonNeg lhs - unFixNonNeg rhs

pub/functora/src/sql/Functora/SqlOrphan.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,11 @@ deriving newtype instance PersistFieldSql FeeRate
112112
deriving newtype instance PersistField ProfitRate
113113

114114
deriving newtype instance PersistFieldSql ProfitRate
115+
116+
deriving newtype instance PersistField Fix
117+
118+
deriving newtype instance PersistFieldSql Fix
119+
120+
deriving newtype instance PersistField FixNonNeg
121+
122+
deriving newtype instance PersistFieldSql FixNonNeg

pub/functora/src/test/Functora/PreludeSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ spec = do
4848
`shouldBe` "uid-11111111111111111111111111111111"
4949
unsafeFrom @(UTF_8 ByteString) @Text (htmlUid $ addUid nilUid nilUid)
5050
`shouldBe` "uid-HXugtXVfQbdnt1bHDJcE9HU6kDMaPEJSQhN3moaHr6Hp"
51+
it "inspectFixed" $ do
52+
inspectFixed @Text (unFix 2.5) `shouldBe` "2.5"
53+
inspectFixed @Text (unFixNonNeg 2.500) `shouldBe` "2.5"
5154
it "parseRatio/overflow"
5255
$ inspect @Text (parseRatio @Text @Word8 @(Either SomeException) "0.333")
5356
`shouldBe` "Left (ParseException {parseExceptionSource = \"0.333\", parseExceptionSourceType = Text, parseExceptionTargetType = Ratio Word8, parseExceptionFailure = \"Word8 numerator or denominator seems to be out of bounds, expected 333 % 1000 but got 77 % 232\"})"

pub/functora/src/test/Functora/TagsSpec.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Functora.Tags.TestFgpt ()
99
import Functora.Tags.TestSing
1010
import Test.Hspec
1111

12-
newMoney :: forall tags. Tagged (tags |+| 'Money) Rational
13-
newMoney = Tagged $ 4 % 5
12+
newMoney :: forall tags. Tagged (tags |+| 'Money) Natural
13+
newMoney = Tagged 4
1414

1515
getSymbolTag ::
1616
forall (tag :: Symbol) tags rep.
@@ -56,17 +56,17 @@ spec = do
5656
`shouldBe` Gain
5757
it "inspect" $ do
5858
inspect @Text (newMoney @NoTags)
59-
`shouldBe` "Tagged (4 % 5)"
59+
`shouldBe` "Tagged 4"
6060
inspect @Text (newMoney @(NoTags |+| "BTC" |+| 'Net))
61-
`shouldBe` "Tagged (4 % 5)"
61+
`shouldBe` "Tagged 4"
6262
inspect @Text (newMoney @(Tags "BTC" |+| 'Net |+| 'Lose |+| 'Merchant))
63-
`shouldBe` "Tagged (4 % 5)"
63+
`shouldBe` "Tagged 4"
6464
inspect @Text (newMoney @(Tags "BTC" |+| 'Net |+| 'Lose))
65-
`shouldBe` "Tagged (4 % 5)"
65+
`shouldBe` "Tagged 4"
6666
inspect @Text (newMoney @(Tags "BTC"))
67-
`shouldBe` "Tagged (4 % 5)"
67+
`shouldBe` "Tagged 4"
6868
inspect @Text (newMoney @(Tags "BTC" |+| 'Net |+| 'Gain))
69-
`shouldBe` "Tagged (4 % 5)"
69+
`shouldBe` "Tagged 4"
7070
it "inspectType" $ do
7171
inspectType @NoTags @Text
7272
`shouldBe` "'[] (Mapping * *)"

0 commit comments

Comments
 (0)