Skip to content

Support two argument at-irrational#46054

Merged
LilithHafner merged 11 commits intomasterfrom
LilithHafner-patch-2
Apr 22, 2023
Merged

Support two argument at-irrational#46054
LilithHafner merged 11 commits intomasterfrom
LilithHafner-patch-2

Conversation

@LilithHafner
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@LilithHafner
Copy link
Copy Markdown
Member Author

Bump

@LilithHafner
Copy link
Copy Markdown
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