Coder Social home page Coder Social logo

Comments (4)

jacg avatar jacg commented on June 29, 2024

Are there any difficulties or pitfalls here, or is it just a fairly mechanical process that simply requires finding the time to do it?

If it's the latter, I'll start chipping away at it.

If it's the former, I could also have a go, if you brief me.

from uom.

iliekturtles avatar iliekturtles commented on June 29, 2024

Should be completely mechanical.

Implementation would start with the following macros

uom/src/system.rs

Lines 588 to 591 in 66d3e85

impl_ops!(Add, add, +, AddAssign, add_assign, +=, Sum,
Mul, mul, *, MulAssign, mul_assign, *=, add_mul);
impl_ops!(Sub, sub, -, SubAssign, sub_assign, -=, Diff,
Div, div, /, DivAssign, div_assign, /=, sub_div);

And you can compare against what the standard library is doing for inspiration on implementing for T and &T. https://doc.rust-lang.org/src/core/ops/arith.rs.html#117-133

Once the major traits are implemented we can go hunting to see if there is anything else like Sub that needs extra impls.

from uom.

jacg avatar jacg commented on June 29, 2024

Implementation would start with the following macros [impl_ops!]

Just to be sure: Are you suggesting to add the implementations of the reference versions, to the bodies of those macros?

I don't quite understand the pattern inside the macro. First we have this group of 4:

  • ....autoconvert! ... AddSubTrait
  • not_autoconvert! ... AddSubTrait
  • ....autoconvert! ... AddSubAssignTrait
  • not_autoconvert! ... AddSubAssignTrait

followed by another group of 4:

  • ....autoconvert! ... MulDivTrait
  • not_autoconvert! ... MulDivTrait
  • ................ ... MulDivTrait
  • ................ ... MulDivAssignTrait

Why is there an asymmetry between the AddSub group and the MulDiv group?

from uom.

iliekturtles avatar iliekturtles commented on June 29, 2024

I apologize for taking so long to get to this. I'll look at the PR in a second to see what you've done so far. The original thought was to do something to the standard library and use a macro that accepts the type (T vs. &T) as a parameter.

The asymmetry is because multiply and divide allow for operating on the underlying storage type as well as the quantity. e.g. length * time and length * 3.0. Add/subtract require the same quantity on both sides of the operator. e.g. length1 + length2. The [not_]autoconvert! macros decide if the implementation supports operating on quantities with different base units.

from uom.

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.