GithubHelp home page GithubHelp logo

Compound assignments? about units HOT 5 CLOSED

nholthaus avatar nholthaus commented on July 16, 2024 1
Compound assignments?

from units.

Comments (5)

nholthaus avatar nholthaus commented on July 16, 2024

I'm not sure it can be done. I could be wrong though, and if so would welcome a patch.

There is some nuance to working with arithmetic operators in the units library. Not sure how deeply you've delved into the code, but unit_t types are a CRTP construct inheriting from a so-called non-linear scale. The idea behind the NLS is that different arithmetic could be supported for different scales. So far, two are supported:

  • linear scale: implements standard arithmetic
  • decibel scale: implements log arithmetic for dB units

You could envision other logarithmic or exponential scales. I even did some testing that showed that datum-shifted scales like the Richter Scale were possible.

My recollection is a bit hazy, but I think when it came to compound assignment, I got foiled by the fact that base-class assignment isn't the same as inherited class assignment, or something like that. Or maybe it was just an oversight.

Additionally, you have to be careful with the enable_if template parameters (mostly not to break implicit conversion of dimensionless units back and forth to the underlying type), and the different RHS types that need to be supported. Copying an existing operator would be a good starting point. I'd encourage you to give it a try, at minimum you'll learn something, and then you could share that knowledge back with us :)

from units.

nholthaus avatar nholthaus commented on July 16, 2024

note to self: maybe possible as non-member?

from units.

nholthaus avatar nholthaus commented on July 16, 2024

I take back what I said, I think this is an easy addition.

from units.

EvanBalster avatar EvanBalster commented on July 16, 2024

Cool, thanks! I had written my own implementation but I'll pull yours down now.

from units.

nholthaus avatar nholthaus commented on July 16, 2024

If you end up making any more improvements, feel free to share them back :)

from units.

Related Issues (20)

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.