Skip to content

Commit 0722b5b

Browse files
jmkuhnstevengj
authored andcommitted
Export exponent10 and ldexp10 (#67)
1 parent 3da1582 commit 0722b5b

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/DecFP.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ using Compat, Compat.Printf, Compat.Unicode
2020
export GC
2121
end
2222

23-
export Dec32, Dec64, Dec128, @d_str, @d32_str, @d64_str, @d128_str
23+
export Dec32, Dec64, Dec128, @d_str, @d32_str, @d64_str, @d128_str, exponent10, ldexp10
2424

2525
# Load libbid from our deps.jl
2626
const depsjl_path = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
@@ -124,6 +124,32 @@ function isnanstr(s::AbstractString)
124124
return true
125125
end
126126

127+
"""
128+
exponent10(x::DecFP.DecimalFloatingPoint)
129+
130+
Get the exponent of the base 10 representation of a normalized floating-point number.
131+
132+
# Examples
133+
```jldoctest
134+
julia> exponent10(Dec64(123))
135+
2
136+
```
137+
"""
138+
exponent10(x::DecimalFloatingPoint)
139+
140+
"""
141+
ldexp10(x::DecFP.DecimalFloatingPoint, n::Integer)
142+
143+
Compute ``x * 10^n``.
144+
145+
# Examples
146+
```jldoctest
147+
julia> ldexp10(Dec64(15), 2)
148+
1500.0
149+
```
150+
"""
151+
ldexp10(x::DecFP.DecimalFloatingPoint, n::Integer)
152+
127153
for w in (32,64,128)
128154
BID = Symbol(string("Dec",w))
129155
Ti = eval(Symbol(string("UInt",w)))

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ for T in (Dec32, Dec64, Dec128)
192192
@test_throws DomainError sqrt(yd)
193193
@test_throws DomainError acosh(zd)
194194

195-
@test DecFP.ldexp10(parse(T, "1"), 3) == 1000
196-
@test DecFP.exponent10(parse(T, "1000")) == 3
195+
@test ldexp10(parse(T, "1"), 3) == 1000
196+
@test exponent10(parse(T, "1000")) == 3
197197
@test sqrt(complex(yd)) sqrt(complex(y))
198198

199199
@test typeof(xd * pi) == T

0 commit comments

Comments
 (0)