Precision of tothe exponents for rounding| is 0.3333 1/3 ? Is 0.333252 1/3 As well
Sometimes we have units with rational exponents \mathrm{unit}^\frac{c}{d}~~{ c,d\in \N}
like \mathrm{unit}^{\frac{1}{3}}\Longrightarrow \sqrt[3]{\mathrm{Unit}}
But in the dsi we don't save \tothe{1/3}
but instead \tothe{0.33333333333333333333}
or \tothe{0.3333}
Leading to my Question:
How extract ratios from this numbers.
Is \tothe{0.3333}
\mathrm{unit}^\frac{3333}{10000} \Longrightarrow \sqrt[3333]{\mathrm{Unit}^{10000}}
Or can i reduce it to
\mathrm{unit}^\frac{1}{3} \Longrightarrow \sqrt[3]{\mathrm{Unit}}
To reduce the rationals various libraries are available, like shown in the ChatGTP answer below.
Common for all the libraries is that they can use a maximal denominator like 1000 or a number of digits 3 in this case to decide when to reduce the integer ratio.
In our example a maximal denominator of 1000 would convert 0.3333 to 1/3 and a denominator of 10000 would lead to 3333/10000
At the moment the maximum denominator is undefined so either i have to make arbitrary assumptions about the precision or beeing unable to correctly process \mathrm{unit}^\frac{1}{3}
Sugestion
Is suggest limiting the precision to 4 digits.
In everyday use units with rational exponents are not super common and if they occur i would assume 99.99% of them being in fact someting like
\mathrm{unit}^\frac{c}{d}~~{ c,d\in \N} \text{ with } c,d \leq100
If we limit the exponent precision to 4 digits the exponent can be properly stored in an f16 and we can reduce the fraction to get the c,d
integers to do proper calculations with them with integer math.
Other option with braking change
An other option would be changing from decimal representation to an integer fraction representation in the \tothe{}
like using a |
for fractions \tothe{1|3}
but this would be an huge braking change.
I will sugest 4 digits precison decimals to the BIPM SI endpoint aswell
CHAT GTP Answer for ratio finding in various Languages
For dealing with the matching of floating-point numbers to their closest fractions within certain programming languages, you might not find a library that does exactly this—matching decimal approximations to fractions based on a lookup table—as it's a very specific task. However, you can leverage existing numerical or mathematical libraries to help implement such functionality. Below are some libraries and functions in C++, Python, MATLAB, Java, and JavaScript that can be useful in building a solution for this problem:
C++
-
Boost Rational Library: Part of the Boost libraries, the Boost Rational Library can be used to work with fractions in C++. While it doesn't provide direct matching from decimal to fraction, it allows for the creation and manipulation of fraction types, which you can use in implementing your lookup or matching logic.
- Website: Boost Rational
Python
-
fractions Module: Python's standard library includes the
fractions
module, which provides support for rational number arithmetic. You can use it to convert floating-point numbers to their closest fractional representation.from fractions import Fraction print(Fraction(0.33333).limit_denominator())
MATLAB
-
Rational Approximation: MATLAB offers functions like
rats
, which provides a rational approximation of numbers. It displays rational approximations of the elements of a matrix, which you could use for matching purposes.format rat disp(0.33333)
Java
-
Apache Commons Math: The Apache Commons Math library provides many mathematical and statistical tools that can be used in Java applications. While it doesn't offer a direct method for matching decimals to fractions, its utilities can assist in implementing such functionality.
- Website: Apache Commons Math
JavaScript
-
Fraction.js: This is a library for fractional arithmetic in JavaScript. It can parse a floating-point number into a fraction and might be used as part of a solution for identifying close matches.
var Fraction = require('fraction.js'); console.log(new Fraction(0.33333).toFraction(true));
- GitHub: Fraction.js
For each of these languages, while a direct "lookup table for decimal-to-fraction based on precision" function may not exist, you can combine the provided library functionalities with custom logic to approximate this behavior. For instance, converting a decimal to its nearest fraction representation and then comparing this against a predefined set of important fractions you wish to match can achieve the desired result.