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

Pow ^ does not compile when using unchained #7

Closed
arkanoid87 opened this issue Nov 14, 2022 · 8 comments
Closed

Pow ^ does not compile when using unchained #7

arkanoid87 opened this issue Nov 14, 2022 · 8 comments

Comments

@arkanoid87
Copy link

import unchained
import measuremancer

let
    a = 2.1.m ± 0.5.m
    b = 1.2.m ± 0.3.m

echo a**b
measuremancer.nim(312, 17) Error: type mismatch: got <Meter, Meter>
but expected one of:
func pow(x, y: float32): float32
  first type mismatch at position: 1
  required type for x: float32
  but expression 'a.val' is of type: Meter
func pow(x, y: float64): float64
  first type mismatch at position: 1
  required type for x: float64
  but expression 'a.val' is of type: Meter
@arkanoid87
Copy link
Author

Speaking of power operator, I think there should also be this version

proc `**`*[T: FloatLike](m: FloatLike, p: Measurement[T]): Measurement[T] =`

@arkanoid87
Copy link
Author

actually, it doesn't work even without units

import unchained
import measuremancer

let
    u = 2.1 ± 0.5
    z = 1.2 ± 0.3

echo u**z
measuremancer.nim(315, 31) Error: type mismatch: got <float>
but expected one of:
func log[T: SomeFloat](x, base: T): T
  first type mismatch at position: 2
  missing parameter: base

math.log wants second base argument
https://nim-lang.org/docs/math.html#log%2CT%2CT

@arkanoid87
Copy link
Author

I need to add that the more I read the code (to hopefully grasp how to create a PR) the more I understand the complexity of unchained integration.

@arkanoid87
Copy link
Author

I've been following the white rabbit until I've decided to properly turn it into tests
#8

@arkanoid87
Copy link
Author

I'm trying some fixes in my fork a5f0689#diff-c3e2bf281e6b65db974cf236911d68cb47f1f0a14bb0029e5354e573fc2da0eb

I fixed power & exponentials when not using unchained (comparing results with vs python uncertainties), but how to deal with float exponents?

Python Pint handles them at runtime using strings

from pint import UnitRegistry

ureg = UnitRegistry()

distance = 24.0 * ureg.meter
print(repr(distance ** 12.5))
print(repr(distance ** distance))

Unchained hates this to live at compile life

<Quantity(1.78912433e+17, 'meter ** 12.5')>
Traceback (most recent call last):
pint.errors.DimensionalityError: Cannot convert from 'meter' to 'dimensionless'
import unchained

echo pow(5.m, 4.2)
Error: type mismatch: got <Meter, float64>
but expected one of:
func pow(x, y: float32): float32
  first type mismatch at position: 1
  required type for x: float32
  but expression 'm(5)' is of type: Meter
func pow(x, y: float64): float64
  first type mismatch at position: 1
  required type for x: float64
  but expression 'm(5)' is of type: Meter

expression: pow(m(5), 4.2)

should I consider units as base or exponent of power/exponential a compile error?

@Vindaar
Copy link
Member

Vindaar commented Nov 15, 2022

Float based exponents simply don't make sense with units attached! What's a 5.kg^{2.3} ? The same is true for trigonometric functions. Their argument must be UnitLess (or an equivalent like Rad).

Haven't had time to properly look yet, sorry.

@arkanoid87
Copy link
Author

No need to be sorry, you wrapped up an amazing system. I just need some time to wrap my head around all of this

@Vindaar
Copy link
Member

Vindaar commented Nov 16, 2022

Closing this, as it should be addressed in version v0.2.2. Feel free to reopen if I missed something.

@Vindaar Vindaar closed this as completed Nov 16, 2022
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