connorferster / forallpeople

Python SI units library: your 'daily driver' for calculations.
Apache License 2.0
307 stars 40 forks source link

Using sqrt with units and .prefix() causes problems #112

Open cream68 opened 1 month ago

cream68 commented 1 month ago

I am using the following lambda function to apply sqrt to variables with units:

sqrt = lambda x: x.sqrt()

This works very well until I force the units using .prefix('something') on the variables used inside the sqrt function:

super(Physical, self).__setattr__("value", float(value))
                                               ^^^^^^^^^^^^
TypeError: float() argument must be a string or a real number, not 'complex'

Is there a way to circumvent this problem or a better approach to ensure sqrtworks with prefixed units?

Thank you for your help!