summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul A. Patience <paul@apatience.com>2022-05-15 10:25:20 -0400
committerPaul A. Patience <paul@apatience.com>2022-05-15 10:25:20 -0400
commit02d76c2157aaa17d6f020164284dd2bacab9058b (patch)
treedcd4baf29a048905fd07626c2c93cd4a2246b055
parent14d39ed3a4f461679a0ad2bc3626a82e7c0a1e62 (diff)
Fix int.Signum on negative numbers
It used to return 0.
-rw-r--r--bigint.bqn2
-rw-r--r--test/big.bqn11
2 files changed, 10 insertions, 3 deletions
diff --git a/bigint.bqn b/bigint.bqn
index 17f0763..efd4593 100644
--- a/bigint.bqn
+++ b/bigint.bqn
@@ -16,5 +16,5 @@ Mul ⇐ Canon ≠○⊑ ⋈ nat.Mul○(1⊸⊑)
_compare ⇐ {=○⊑◶⟨𝔽○(¬⊑), ⊑∘⊢◶({𝕏nat._compare○(1⊸⊑)}¨⟨𝔽,𝔽˜⟩)⟩}
-Signum ⇐ -˜⟜nat.Signum´
+Signum ⇐ ⊑◶⟨nat.Signum 1⊸⊑,¯1⟩
Conj ⇐ ⊢
diff --git a/test/big.bqn b/test/big.bqn
index 41694d5..69f8630 100644
--- a/test/big.bqn
+++ b/test/big.bqn
@@ -3,7 +3,7 @@ i10 ← ⟨10⟩ •Import "../bigint.bqn"
_fails ← {0∘𝔽⎊1}
-TestNat ← { 𝕊 ⟨Add,Sub,Mul,_compare⟩‿S:
+TestNat ← { 𝕊 ⟨Add,Sub,Mul,_compare,Signum⟩‿S:
! "41401" ≡ "41099" Add⌾S "302"
! "" (Add≡⊢)○S "9120"
@@ -22,9 +22,12 @@ TestNat ← { 𝕊 ⟨Add,Sub,Mul,_compare⟩‿S:
! 0 CC "90"‿"90"
! 0 CC ""‿""
! ¯1 CC "99"‿"100"
+
+ ! 0 = Signum S ""
+ ! 1 = Signum S "1"
}
-TestInt ← { 𝕊 ⟨Add,Sub,Mul,_compare⟩‿S:
+TestInt ← { 𝕊 ⟨Add,Sub,Mul,_compare,Signum⟩‿S:
! "-215" S⊸≡ "-96" Add○S "-119"
! "23" S⊸≡ "-96" Add○S "119"
@@ -40,6 +43,10 @@ TestInt ← { 𝕊 ⟨Add,Sub,Mul,_compare⟩‿S:
! 0 CC "-90"‿"-90"
! 0 CC ""‿""
! ¯1 CC "-1010"‿""
+
+ ! ¯1 = Signum S "-1"
+ ! 0 = Signum S ""
+ ! 1 = Signum S "1"
}
Dig ← ⌽-'0'˙