Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for @decimal macro #57

Open
michikawa07 opened this issue Dec 6, 2023 · 1 comment
Open

Proposal for @decimal macro #57

michikawa07 opened this issue Dec 6, 2023 · 1 comment

Comments

@michikawa07
Copy link

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  
@michikawa07
Copy link
Author

michikawa07 commented Dec 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant