feat: add order of magnitude length conversion #985
Merged
+471
−0
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