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

Fix macro hygiene in @constant, @derived_constant (missing esc()) #36

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

Socob
Copy link
Contributor

@Socob Socob commented Oct 7, 2024

The constant definition macros have some issues where not all inputs are escaped using esc(), so that existing variables cannot be referred to in some of the arguments. For example, this affects the val argument of @constant and @derived_constant (but not the corresponding def). I suspect this is why derived constants have their Float64 values (but not their BigFloat values!) hard-coded using float literals instead of referring to previously defined constants, e. g.

@derived_constant(ReducedPlanckConstant, ħ, "Reduced Planck constant",
1.0545718176461565e-34, ustrip(big(h))/(2 * big(pi)), J * s,

@derived_constant(MolarGasConstant, R, "Molar gas constant", 8.314_462_618_153_24,
ustrip(big(N_A) * big(k_B)), J * mol^-1 * K^-1,

@derived_constant(StefanBoltzmannConstant, σ, "Stefan-Boltzmann constant", 5.670_374_419_184_4294e-8,
ustrip(2 * big(pi) ^ 5 * big(k_B) ^ 4 / (15 * big(h) ^ 3 * big(c_0) ^ 2)), W * m^-2 * K^-4,

This PR fixes the macro hygiene issues and changes these constant definitions to avoid unnecessary hard-coded values. I’ve checked that the resulting Float64 values are the same as those that were previously hard-coded.

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.75%. Comparing base (7d94def) to head (1b7d302).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #36      +/-   ##
==========================================
+ Coverage   93.50%   93.75%   +0.24%     
==========================================
  Files           3        3              
  Lines          77       80       +3     
==========================================
+ Hits           72       75       +3     
  Misses          5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@giordano
Copy link
Member

giordano commented Oct 7, 2024

Thanks!

@giordano giordano merged commit 72782d8 into JuliaPhysics:master Oct 7, 2024
12 checks passed
@Socob Socob deleted the fix-constant-macro-hygiene branch October 7, 2024 17:18
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

Successfully merging this pull request may close these issues.

2 participants