feat: add order of magnitude length conversion#985
Merged
siriak merged 1 commit intoTheAlgorithms:masterfrom Dec 31, 2025
Merged
Conversation
Contributor
Author
|
@siriak, this is ready to be merged. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #985 +/- ##
==========================================
- Coverage 95.77% 95.76% -0.02%
==========================================
Files 354 355 +1
Lines 23407 23624 +217
==========================================
+ Hits 22419 22624 +205
- Misses 988 1000 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
siriak
approved these changes
Dec 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a comprehensive implementation of metric length unit conversion to the conversions module. The implementation supports conversions between nine metric length units ranging from meters to yottametres ($10^{24}$ meters).
Implementation Details
The implementation provides:
MetricLengthUnitenum - Type-safe representation of length unitsconvert_metric_length(value: f64, from: MetricLengthUnit, to: MetricLengthUnit) -> f64metric_length_conversion(value: f64, from_type: &str, to_type: &str) -> Result<f64, String>Algorithm Details
The conversion uses the formula:
Where each unit has an exponent representing its power of 10 relative to meters.
Example:
Time Complexity:$O(1)$ - constant time conversion$O(1)$ - no additional space needed
Space Complexity:
Design Choices
convert_metric_length) and string-based (metric_length_conversion) functionsResulttype for proper Rust error handlinglength_conversionmoduleChanges Made
src/conversions/order_of_magnitude_conversion.rswith complete implementationsrc/conversions/mod.rsto include and export the moduleType of Change
Testing
All tests pass successfully:
Test Coverage
✅ Unit Tests (30+ tests)
Examples
Checklist
cargo fmtcargo clippyAdditional Context
{}in stringsStandards Compliance:
References