Code Monkey home page Code Monkey logo

Comments (6)

giordano avatar giordano commented on August 25, 2024 1

I've opened a PR for Unitful.jl defining AbstractQuantity: PainterQubits/Unitful.jl#204 If it gets merged, I've already a branch for this package to achieve these cool features:

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 Float64 values of the constants.

from physicalconstants.jl.

Datseris avatar Datseris commented on August 25, 2024

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....

from physicalconstants.jl.

BeastyBlacksmith avatar BeastyBlacksmith commented on August 25, 2024

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.
I forked the old PhysicalConstants and gave it a global switch, so you can change from Value with Dimension to Values without dimension by calling something like switch_units(), don't know if it is of any use for your implementation thogh.
Regarding the abstract type in Unitful.jl you could play with it on your own fork and make a PR if it works out.

from physicalconstants.jl.

giordano avatar giordano commented on August 25, 2024

@Datseris regarding how this package works internally, it defines a new Constant type, which is very similar to Base.Irrational in spirit (and also in code): each constant is a singleton (empty struct) for which various methods are defined.

The most useful feature of this approach is that you get arbitrary precision values for the physical constants (just like the Base.Irrational mathematical constants), even if you change the precision of BigFloat.

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 ustrip(float(c)) (or, even better, with ustrip(c) if I define an appropriate method for ustrip)

from physicalconstants.jl.

carstenbauer avatar carstenbauer commented on August 25, 2024

+1 for AbstractQuantity

from physicalconstants.jl.

giordano avatar giordano commented on August 25, 2024

I've opened an issue at Unitful.jl: PainterQubits/Unitful.jl#186

from physicalconstants.jl.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.