Skip to content

Commit

Permalink
Added module for number sign(um)s.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jul 16, 2024
1 parent d64d5be commit 54fa00b
Show file tree
Hide file tree
Showing 53 changed files with 257 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
[math
[number
["n" natural]
[integer
["i[0]" /32]]]]
["i[0]" /32
["[1]" integer]]]]
[macro
["^" pattern]
["[0]" template]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
[math
[number
["n" natural]
[integer
["i[0]" /32]]]]
["i[0]" /32
["[1]" integer]]]]
[macro
["[0]" template]]
[type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
["[0]" dictionary]]]
[math
[number
[integer
["[0]" /32]]]]
["[0]" /32
["[1]" integer]]]]
[macro
["[0]" template]]
[target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
[math
[number
["n" natural]
[integer
["i[0]" /32]]]]
["i[0]" /32
["[1]" integer]]]]
[macro
["^" pattern]
["[0]" template]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
["[0]" list]]]
[math
[number
[integer
["i[0]" /32]]]]
["i[0]" /32
["[1]" integer]]]]
[target
[jvm
["_" bytecode (.only Bytecode)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
[number
["n" natural]
["i" integer]
[integer
["[0]" /32]]]]
["[0]" /32
["[1]" integer]]]]
[target
[jvm
["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
[number
["n" natural]
["[0]" i64]
[integer
["i[0]" /32]]]]
["i[0]" /32
["[1]" integer]]]]
[macro
["[0]" template]]
[target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
[math
[number
["n" natural]
[integer
["i[0]" /32]]]]
["i[0]" /32
["[1]" integer]]]]
[macro
["[0]" template]]
[target
Expand Down
7 changes: 7 additions & 0 deletions stdlib/source/library/lux/data/bit.lux
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@

_
{try.#Failure ..not_valid}))))

(the .public (xor left right)
(-> Bit Bit
Bit)
(if left
(not right)
right))
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
["[0]" nominal]]
[macro
["[0]" template]]]]
["[0]" // (.only)
[//
["[0]" natural]
["[0]" i64]]])
[///
["//" integer]
["[0]" natural]
["[0]" i64]])

(the .public for
(template.macro (_ ,size ,injection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
["[0]" nominal]]
[macro
["[0]" template]]]]
["[0]" // (.only)
[//
["[0]" i64]]])
[///
["//" natural]
["[0]" i64]])

(the .public for
(template.macro (_ ,size ,injection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
[data
["[0]" binary
["[1]" \\injection]]]]]
[//
["[0]" /08]
[//
["[0]" natural]]])
[///
["[0]" /08
["[1]" integer]]
["[0]" natural]])

(/08.for (natural.+ /08.size /08.size)
binary.bits_16)
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
[data
["[0]" binary
["[1]" \\injection]]]]]
["[0]" // (.only)
["[0]" /08]])
[///
["//" natural]
["[0]" /08
["[1]" natural]]])

(/08.for (//.+ /08.size /08.size)
binary.bits_16)
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
[data
["[0]" binary
["[1]" \\injection]]]]]
[//
["[0]" /08]
["[0]" /16]
[//
["[0]" natural]]])
[///
["[0]" /08
["[1]" integer]]
["[0]" /16
["[1]" integer]]
["[0]" natural]])

(/08.for (natural.+ /16.size /16.size)
binary.bits_32)
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
[data
["[0]" binary
["[1]" \\injection]]]]]
["[0]" // (.only)
["[0]" /08]
["[0]" /16]])
[///
["//" natural]
["[0]" /08
["[1]" natural]]
["[0]" /16
["[1]" natural]]])

(/08.for (//.+ /16.size /16.size)
binary.bits_32)
21 changes: 12 additions & 9 deletions stdlib/source/library/lux/math/number/big/integer.lux
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@
[//
["//_64" natural]
["/_64" integer]
["[0]" signum]
[//
[arithmetic (.only Arithmetic)]]]])

(the with_template (.in_module# .prelude .with_template))
(the macro (.in_module# .prelude .template#macro))

(every .public Signum
Bit)
(with_template [,value ,character ,signum]
[(the ,value
(its signum.#value ,signum))

(the .public positive 0b)
(the .public negative 1b)
(the ,character
(its signum.#character ,signum))]

[positive positive_signum signum.positive]
[negative negative_signum signum.negative]
)

(every .public Number
(Record
[... https://en.wikipedia.org/wiki/Sign_function
#signum Signum
#signum signum.Value
... https://en.wikipedia.org/wiki/Absolute_value
#absolute //.Number]))

Expand Down Expand Up @@ -217,7 +223,7 @@
(when [origin it]
[[signum_of_origin origin]
[signum_of_it it]]
[#signum (bit.= signum_of_origin signum_of_it)
[#signum (signum.x signum_of_origin signum_of_it)
#absolute (,// origin it)]))]

[x //.x]
Expand Down Expand Up @@ -387,9 +393,6 @@
[multiplication ..x ..positive_one]
)

(the positive_signum "+")
(the negative_signum "-")

(the not_valid
(error "Not an integer."))

Expand Down
10 changes: 8 additions & 2 deletions stdlib/source/library/lux/math/number/integer.lux
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
["[0]" //
["[1][0]" natural]
["[1][0]" i64]
["[0]" signum]
[//
[arithmetic (.only Arithmetic)]]])

Expand Down Expand Up @@ -267,8 +268,13 @@
[minimum ..minor (by ..interval maximum)]
)

(the -sign "-")
(the +sign "+")
(with_template [,character ,signum]
[(the ,character
(its signum.#character ,signum))]

[+sign signum.positive]
[-sign signum.negative]
)

(with_template [<struct> <format> <error>]
[(the .public <struct>
Expand Down
34 changes: 34 additions & 0 deletions stdlib/source/library/lux/math/number/signum.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.using
[library
[lux (.except)
[data
["[0]" bit]]]])

(the with_template (.in_module# .prelude .with_template))

... https://en.wikipedia.org/wiki/Sign_function
(every .public Value
Bit)

(the .public x
(-> Value Value
Value)
bit.xor)

(every .public Signum
(Record
[#character Text
#value Value]))

(with_template [,name ,character ,value]
[(the .public ,name
Signum
[#character ,character
#value ,value])]

[positive "+" 0b]
[negative "-" 1b]
)
7 changes: 4 additions & 3 deletions stdlib/source/library/lux/target/jvm/attribute.lux
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
[math
[number
["n" natural]
[natural
["[0]" /16]
["[0]" /32]]]]
["[0]" /16
["[1]" natural]]
["[0]" /32
["[1]" natural]]]]
[macro
["[0]" expansion]
["[0]" template]]]]
Expand Down
7 changes: 4 additions & 3 deletions stdlib/source/library/lux/target/jvm/attribute/code.lux
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
[math
[number
["n" natural]
[natural
["[0]" /16]
["[0]" /32]]]]]]
["[0]" /16
["[1]" natural]]
["[0]" /32
["[1]" natural]]]]]]
["[0]" ///
[bytecode
[environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
[math
[number
["n" natural]
[natural
["[0]" /16]]]]]]
["[0]" /16
["[1]" natural]]]]]]
["[0]" //
["//[1]" ///
["[1][0]" index (.only Index)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
[math
[number
["n" natural]
[natural
["[0]" /16]]]]]])
["[0]" /16
["[1]" natural]]]]]])

(every .public Entry
(Record
Expand Down
11 changes: 6 additions & 5 deletions stdlib/source/library/lux/target/jvm/bytecode.lux
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
[number
["n" natural]
["i" integer]
[natural
["n[0]" /08]
["n[0]" /16]]
[integer
["[0]" /32]]]]
["n[0]" /08
["[1]" natural]]
["n[0]" /16
["[1]" natural]]
["[0]" /32
["[1]" integer]]]]
[macro
["[0]" template]
["[0]" expansion]]
Expand Down
8 changes: 4 additions & 4 deletions stdlib/source/library/lux/target/jvm/bytecode/address.lux
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
[math
[number
["n" natural]
[natural
["[0]" /16]]
[integer
["[0]" /32]]]]
["[0]" /16
["[1]" natural]]
["[0]" /32
["[1]" integer]]]]
[type
["[0]" nominal]]]]
[//
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/target/jvm/bytecode/environment.lux
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
["[0]" template]]
[math
[number
[natural
["[0]" /16]]]]]]
["[0]" /16
["[1]" natural]]]]]]
[/
["/[0]" limit (.only Limit)
["/[0]" stack (.only Stack)]
Expand Down
Loading

0 comments on commit 54fa00b

Please sign in to comment.