Skip to content

Commit

Permalink
Merge pull request #79 from oscardssmith/patch-2
Browse files Browse the repository at this point in the history
avoid overflow on `exp` and friends.
  • Loading branch information
milankl committed Jan 30, 2023
2 parents 679edd9 + e1fe713 commit 05c9cd8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/arithmetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ for op in (:(+), :(-), :(*), :(/), :(^))
end

# ONE ARGUMENT ARITHMETIC, sqrt, exp, log, etc. via conversion
for op in (:sqrt, :exp, :exp2, :exp10, :expm1, :log, :log2, :log10, :log1p,
for op in (:sqrt, :cbrt, :log, :log2, :log10, :log1p,
:sin, :cos, :tan, :sinpi, :cospi)
@eval begin
Base.$op(x::T) where {T<:AbstractPosit} = convert(T,$op(float(x)))
end
end

for op in (:exp, :exp2, :exp10, :expm1)
@eval begin
function Base.$op(x::T) where {T<:AbstractPosit}
val = $op(float(x))
isinf(val) ? floatmax(T) : convert(T, val)
end
end
end

Base.sincos(x::AbstractPosit) = sin(x),cos(x) # not in eval loop because of convert
Base.sincospi(x::AbstractPosit) = sinpi(x),cospi(x) # not in eval loop because of convert

Expand Down

0 comments on commit 05c9cd8

Please sign in to comment.