-
Notifications
You must be signed in to change notification settings - Fork 16
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
FEAT: Convert numeric to prefixed value function #159
base: main
Are you sure you want to change the base?
Conversation
Hey, thanks for the contribution! So I'm comparing your function to one that does something pretty similar called However, it doesn't scale the decimal to the most probable choice So, two things that I'd recommend before pulling this:
from hdl21 import Prefixed
from hdl21.prefix import MILLI
a = Prefixed(0.001234)
assert a == Prefixed(number=Decimal('1.234'),prefix=MILLI) |
Sounds good! I'll send an updated one |
Codecov Report
@@ Coverage Diff @@
## main #159 +/- ##
==========================================
+ Coverage 87.19% 87.22% +0.02%
==========================================
Files 109 109
Lines 9568 9590 +22
==========================================
+ Hits 8343 8365 +22
Misses 1225 1225
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Looking great! A few thoughts:
Related to, but not part of this PR - def _scale_to_smaller(
me: Prefixed, other: Union[Prefixed, ToPrefixed]
) -> Tuple[Prefixed, Prefixed]:
"""# Scale two `Prefixed` numbers to the smaller of the two prefixes.
The `me` argument is always a `Prefixed`, generally due to being the `self` in a `Prefixed` mthod.
The `other` argument is commonly another compatible/ convertible type,
and is converted before scaling."""
other = to_prefixed(other)
smaller = me.prefix if me.prefix.value < other.prefix.value else other.prefix
return me.scale(smaller), other.scale(smaller) It seems that, without such "normalization"/ "regularization"/ whatever-it's-called... this can be wrong? |
|
All sounds great and cheers for all your work on this really good software. Sorry, I am away of my computer until next week or would help sooner!
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Thomas Pluck ***@***.***>
Sent: Thursday, July 20, 2023 8:31:39 PM
To: dan-fritchman/Hdl21 ***@***.***>
Cc: Dario Antonio Quintero Dominguez ***@***.***>; Author ***@***.***>
Subject: Re: [dan-fritchman/Hdl21] FEAT: Convert numeric to prefixed value function (PR #159)
* Not sure there is a dedicated term for picking the common-sense SI prefix, guess you could go with "autoscale"
* That is a goofy code snippet, I'll roll in a fix with this PR
—
Reply to this email directly, view it on GitHub<#159 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AIO5PRGQ75TG5DOJGCTHKTLXRGBRXANCNFSM6AAAAAA2M55WBM>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Hi Dan,
Hope you are well! I find this function useful and maybe it could be handy for others.
It works like:
I've included this in a test too. Just in case it is of any use.