at the julia command line, run: Pkg.clone("git://github.com/REX-computing/unumjl.git", "Unums")
at the prompt, type:
using Unums
You may now use unums. To convert floating points or integers to unums, use the convert function. Note that the conversion currently assumes that floating points represent exact values, even if the human-input value cannot be exact.
To retrieve the unum value, as a human-readable form, I recommend the describe()
function which converts Unums and Ubounds to human-readable format. In the future,
this input format will be natively parseable in julia to generate the appropriate
unum.
The standard mathematical operators are overloaded to allow easy calculation with Unums.
julia> x = Unum{3,4}(4.3)
Unum{3,4}(0x0000000000000003, 0x1333000000000000, 0x0001, 0x0001, 0x000F)
julia> y = one(Unum{3,4})
Unum{3,4}(0x0000000000000001, 0x0000000000000000, 0x0000, 0x0001, 0x0000)
julia> x + y
Unum{3,4}(0x0000000000000003, 0x5333000000000000, 0x0001, 0x0001, 0x000F)
julia> describe(x + y)
Unum{3,4}(5.29998779296875 op → 5.300048828125 op)
julia> x = one(Unum{3,4})
Unum{3,4}(0x0000000000000001, 0x0000000000000000, 0x0000, 0x0001, 0x0000)
julia> y = Unum{3,4}(3)
Unum{3,4}(0x0000000000000001, 0x8000000000000000, 0x0000, 0x0000, 0x0000)
julia> x / y
Unum{3,4}(0x0000000000000001, 0x5555000000000000, 0x0001, 0x0002, 0x000F)
julia> describe(x / y)
Unum{3,4}(0.3333320617675781 op → 0.33333587646484375 op)
julia> x = one(Unum{4,7})
Unum{4,7}(0x0000000000000001, UInt64[0x0000000000000000,0x0000000000000000], 0x0000, 0x0001, 0x0000)
julia> y = Unum{4,7}(3)
Unum{4,7}(0x0000000000000001, UInt64[0x8000000000000000,0x0000000000000000], 0x0000, 0x0000, 0x0001)
julia> x / y
Unum{4,7}(0x0000000000000001, UInt64[0x5555555555555555,0x5555555555555555], 0x0001, 0x0002, 0x007F)
julia> describe(x / y)
Unum{4,7}(3.333333333333333333333333333333333333330884386769120234358398465547453654837878e-01 op → 3.333333333333333333333333333333333333338231226461759531283203068905092690324244e-01 op)
To observe the intended "bits" values as they are in "The End of Error", use the
builtin bits(::Unum) function, bits(::Unum, ::String) will insert a spacer.
Support for this work came in part from the following sources:
DARPA Contract D15PC00135 awarded to REX Computing, Inc,
DARPA Contract HR0011-17-9-0007 awarded to Etaphase, Inc.
请发表评论