-
Notifications
You must be signed in to change notification settings - Fork 24
/
Decimals.jl
43 lines (32 loc) · 903 Bytes
/
Decimals.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Pure Julia decimal arithmetic
# @license MIT
# @author jack@tinybike.net (Jack Peterson), 7/3/2014
__precompile__()
module Decimals
import Base: ==, +, -, *, /, <, float, inv
if VERSION < v"0.7.0-DEV.3449"
import Base: normalize
else
export normalize
end
export Decimal,
decimal,
number
DIGITS = 20
# Numerical value: (-1)^s * c * 10^q
struct Decimal <: Real
s::Integer # sign can be 0 (+) or 1 (-)
c::BigInt # coefficient (significand), must be non-negative
q::Integer # exponent
end
# Convert between Decimal objects, numbers, and strings
include("decimal.jl")
# Decimal normalization
include("norm.jl")
# Addition, subtraction, negation, multiplication
include("arithmetic.jl")
# Equality
include("equals.jl")
# Rounding
include("round.jl")
end