Wikipedia reference: https://en.wikipedia.org/wiki/Binary_prefix Wikipedia reference: https://en.wikipedia.org/wiki/International_System_of_Units >>> convert_si_prefix(1, SIUnit.giga, SIUnit.mega) 1000 >>> convert_si_prefix(1, SIUnit.mega, SIUnit.giga) 0.001 >>> convert_
(
known_amount: float,
known_prefix: str | SIUnit,
unknown_prefix: str | SIUnit,
)
| 42 | |
| 43 | |
| 44 | def convert_si_prefix( |
| 45 | known_amount: float, |
| 46 | known_prefix: str | SIUnit, |
| 47 | unknown_prefix: str | SIUnit, |
| 48 | ) -> float: |
| 49 | """ |
| 50 | Wikipedia reference: https://en.wikipedia.org/wiki/Binary_prefix |
| 51 | Wikipedia reference: https://en.wikipedia.org/wiki/International_System_of_Units |
| 52 | >>> convert_si_prefix(1, SIUnit.giga, SIUnit.mega) |
| 53 | 1000 |
| 54 | >>> convert_si_prefix(1, SIUnit.mega, SIUnit.giga) |
| 55 | 0.001 |
| 56 | >>> convert_si_prefix(1, SIUnit.kilo, SIUnit.kilo) |
| 57 | 1 |
| 58 | >>> convert_si_prefix(1, 'giga', 'mega') |
| 59 | 1000 |
| 60 | >>> convert_si_prefix(1, 'gIGa', 'mEGa') |
| 61 | 1000 |
| 62 | """ |
| 63 | if isinstance(known_prefix, str): |
| 64 | known_prefix = SIUnit[known_prefix.lower()] |
| 65 | if isinstance(unknown_prefix, str): |
| 66 | unknown_prefix = SIUnit[unknown_prefix.lower()] |
| 67 | unknown_amount: float = known_amount * ( |
| 68 | 10 ** (known_prefix.value - unknown_prefix.value) |
| 69 | ) |
| 70 | return unknown_amount |
| 71 | |
| 72 | |
| 73 | def convert_binary_prefix( |
nothing calls this directly
no outgoing calls
no test coverage detected