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

Unable to make DerivedUnits with Squared/Exponential Denominators #6

Closed
jlambright opened this issue Mar 6, 2025 · 3 comments
Closed

Comments

@jlambright
Copy link

I've tried to accomplish this in many ways, but they all fall flat on their face. I need to be able to create acceleration units. Are there any best practices?

@mongoose13
Copy link
Owner

mongoose13 commented Mar 11, 2025 via email

@mongoose13
Copy link
Owner

mongoose13 commented Mar 11, 2025 via email

@mongoose13
Copy link
Owner

OK, I'm back at a computer. You should ideally use the third-order constructor:

final metersPerSecond = DerivedUnit3<UnitNumerator<Distance>,
      UnitDenominator<Time>, UnitDenominator<Time>, Distance, Time, Time>.from(
    UnitNumerator<Distance>(meters),
    UnitDenominator(seconds),
    UnitDenominator(seconds),
  );

You can convert between any of these, i.e.:

final milesPerHourPerMinute = DerivedUnit3<UnitNumerator<Distance>,
      UnitDenominator<Time>, UnitDenominator<Time>, Distance, Time, Time>.from(
    UnitNumerator<Distance>(miles),
    UnitDenominator(hours),
    UnitDenominator(minutes),
  );

print(metersPerSecond(3.0).butAs(milesPerHourPerMinute).withPrecision(4));
// 402.6 mi⋅h⁻¹⋅min⁻¹

Let me know if you have issues with this.

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

No branches or pull requests

2 participants