-
Notifications
You must be signed in to change notification settings - Fork 27
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
microbit.scale()
returns a float from integer inputs
#121
Comments
I did consider the integer/float return case. But I don't see an easy way to define |
The main use-case we have for the
Do you mean how to define typings? Or something else? Would it be possible to return an integer if the input value and the "to" arguments are integers? And a float if any of those is a float? I guess in this case we'd still have two options for the internal calculations: To do them as integers or to calculate as floats and covert (or not) the final value. The second option (calc floats, convert to int if necessary) is more accurate but less performant, but might be required or in some cases integer division might not be good enough. Other than performance, would there be any disadvantages of doing that? We'd need to document the int vs float output, so if somebody wants to do something like I guess an alternative could be to have an additional parameter? Something like |
I did initially think this, but then consider (from your comment #102 (comment)):
If you pass in an integer
This could be a solution, to make it very explicit that the values/types passed to
I think that adds extra complexity which is not needed (although the output function could be a clamping function...). |
So having the output being an integer or a float based on the type of the
Or
I'm thinking if any of the tuple values in Does that sound good? Would there be any other simpler ways to approach it, implementation-wise? |
Addresses issue #121. Signed-off-by: Damien George <damien@micropython.org>
I have implemented this in 7f9c32e (it was quite simple to do). |
If we agree on this implementation, micro:bit v1 needs updating as well. |
Thanks Damien! And yes, we will need to update v1 as well with this change 👍 |
micro:bit v1 is updated. I think we can close this issue now. |
For example, with code like this we get an error as
scale()
is returning a float:The text was updated successfully, but these errors were encountered: