aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/number/i64.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/number/i64.lux35
1 files changed, 31 insertions, 4 deletions
diff --git a/stdlib/source/lux/data/number/i64.lux b/stdlib/source/lux/data/number/i64.lux
index 8dfec1fc7..ea4b1987f 100644
--- a/stdlib/source/lux/data/number/i64.lux
+++ b/stdlib/source/lux/data/number/i64.lux
@@ -4,6 +4,8 @@
[equivalence (#+ Equivalence)]
[hash (#+ Hash)]
[monoid (#+ Monoid)]]
+ [control
+ ["." try]]
[data
[number
["n" nat]]]])
@@ -125,8 +127,8 @@
(structure: #export equivalence
(All [a] (Equivalence (I64 a)))
- (def: (= parameter subject)
- ("lux i64 =" parameter subject)))
+ (def: (= reference sample)
+ ("lux i64 =" reference sample)))
(structure: #export hash
(All [a] (Hash (I64 a)))
@@ -140,13 +142,38 @@
(All [a] (Monoid (I64 a)))
(def: identity <identity>)
- (def: compose <compose>)
- )]
+ (def: compose <compose>))]
[disjunction ..false ..or]
[conjunction ..true ..and]
)
+(template [<swap> <size> <pattern>]
+ [(def: <swap>
+ (All [a] (-> (I64 a) (I64 a)))
+ (let [high (try.assume (\ n.binary decode <pattern>))
+ low (..rotate-right <size> high)]
+ (function (_ value)
+ (..or (..logic-right-shift <size> (..and high value))
+ (..left-shift <size> (..and low value))))))]
+
+ [swap/32 32 "1111111111111111111111111111111100000000000000000000000000000000"]
+ [swap/16 16 "1111111111111111000000000000000011111111111111110000000000000000"]
+ [swap/08 08 "1111111100000000111111110000000011111111000000001111111100000000"]
+ [swap/04 04 "1111000011110000111100001111000011110000111100001111000011110000"]
+ [swap/02 02 "1100110011001100110011001100110011001100110011001100110011001100"]
+ [swap/01 01 "1010101010101010101010101010101010101010101010101010101010101010"]
+ )
+
+(def: #export reverse
+ (All [a] (-> (I64 a) (I64 a)))
+ (|>> ..swap/32
+ ..swap/16
+ ..swap/08
+ ..swap/04
+ ..swap/02
+ ..swap/01))
+
(signature: #export (Sub size)
(: (Equivalence (I64 size))
&equivalence)