Decimals.jl
Decimals.jl copied to clipboard
Proposal for @decimal macro
Would the following macros be useful?
julia> macro decimal(ex)
trans!(e::Real) = :(Decimal($e))
trans!(e::Expr) = begin
for (i,a) in enumerate(e.args)
a isa Integer && continue
a isa Real && (e.args[i] = Decimal(a))
a isa Expr && trans!(a)
end
ex
end
:(number($(trans!(ex))))
end
@decimal (macro with 1 method)
julia> 100 * 1.1576
115.75999999999999
julia> @decimal 100 * 1.1576
115.76
This implementation is very rough, but it works well enough to explain my concept.
That is, I expect the expression to be decimalized simply by prefixing it with @decimal.