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

Support two argument at-irrational #46054

Merged
merged 11 commits into from
Apr 22, 2023
Merged

Support two argument at-irrational #46054

merged 11 commits into from
Apr 22, 2023

Conversation

LilithHafner
Copy link
Member

@irrational logten 2.302585092994046 log(big(10))
# can now become
@irrational logten log(big(10))

Needs tests; I'll add them if folks think this is a good idea.

irrational(sym, val, def)
end
macro irrational(sym, def)
irrational(sym, Float64(eval(def)), def)
Copy link
Member

@simeonschaub simeonschaub Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely don't want to call eval inside a macro. Why not:

Suggested change
irrational(sym, Float64(eval(def)), def)
irrational(sym, :(Float64($def)), def)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this would be better, but still has the problem of potentially allocating a new BigFloat each time Float64(::Irrational) is called. In this case the macro should generate a let binding for the value around those method definitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't totally understand macro programming, but when I tested @simeonschaub's suggestion I got

ERROR: MethodError: no method matching Float32(::Expr)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've figured it out and implemented what @JeffBezanson recommended.

@LilithHafner
Copy link
Member Author

I don't think the @irrational macro is currently tested at all (grep -r @irrational test), and I'm not sure how to write a test for it. I'd appreciate advice.

@KristofferC
Copy link
Member

Should the existing @irrational usages switch to this form now?

@LilithHafner
Copy link
Member Author

Bump

@LilithHafner
Copy link
Member Author

Bump. Is there anything else this needs?

@LilithHafner LilithHafner added maths Mathematical functions merge me PR is reviewed. Merge when all tests are passing labels Apr 21, 2023
@LilithHafner LilithHafner merged commit 9c4724b into master Apr 22, 2023
@LilithHafner LilithHafner deleted the LilithHafner-patch-2 branch April 22, 2023 00:11
@LilithHafner LilithHafner removed the merge me PR is reviewed. Merge when all tests are passing label Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants