-
Notifications
You must be signed in to change notification settings - Fork 15
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
Automatic conversion of Constant to Quantity #2
Comments
I totally agree that the objects exported by this Module should be immediatelly useable in mathematical operations. I do not think that an explicit conversion should first be done, as this typically means that it is faster to copy paste the wikipedia value :D I won't comment on how this should be done internally however. I don't have enough experience with coding this package or Uniful.... |
First of all, I'm glad someone takes another hit on this topic. There was a Package with the same name in the past: https://github.com/DataWookie/PhysicalConstants.jl and another that extracts the Data directly from CODATA: https://github.com/kofron/CODATA.jl, but both are unmaintained today. |
@Datseris regarding how this package works internally, it defines a new The most useful feature of this approach is that you get arbitrary precision values for the physical constants (just like the You know, apart from some constants that are defined to be exact (without uncertainty), all physical constants are currently measured with precision much lower than that of double precision floating-point numbers. Thus, it may look an overkill to use arbitrary precision for calculations involving physical constants, but I think that Julia should be ready for the era of high-precision measurements 😄 @BeastyBlacksmith thanks for pointing those packages out. Probably I came across them long time ago and didn't like how they worked. Indeed, I've been thinking about this package for a while now. I don't think I like the idea of having a constant without units, the choice of the reference units would be then arbitrary. However, the user is free to strip the units with |
+1 for |
I've opened an issue at |
I've opened a PR for julia> using PhysicalConstants.CODATA2014
julia> 2c
5.99584916e8 m s^-1
julia> sqrt((h/2pi) * G / c^3) # Planck length, the units are just metres
1.6162283730808862e-35 J^1/2 s kg^-1/2
julia> α
Fine-structure constant (α)
Value = 0.0072973525664
Standard uncertainty = 1.7e-12
Relative standard uncertainty = 2.3e-10
Reference = CODATA 2014
julia> α/2
0.0036486762832
julia> typeof(α/2)
Float64 😃 However this needs improvement as it currently works only with |
In order to use a
Constant
in mathematical operations one has to explicitly convert it to aQuantity
withfloat()
. I think that it's good that the user has to explicitly require the uncertainty withmeasurement(x)
, this is something that may not be always needed.My desire is to make the conversion to
Quantity
, without uncertainty, automatic. I initially thought that promotion rules would have helped, but I found out that they're quite useless for this (you almost never want to promote aConstant
and another number to a common type).I see the following options:
Constant
objectsUnitful.jl
maintainer to define anAbstractQuantity
type that can be subclassed.Constant
could then be a subtype ofAbstractQuantity
and automatically benefits from all the mathematical operations defined there, without duplicating the work here.Please share your thoughts on this.
The text was updated successfully, but these errors were encountered: