Ansicht
Dokumentation

/SAPAPO/EOG_MATH_CONV_TO_FRACT - Convert Number into Fraction with Max. z-Digit Numerator/Denominator

/SAPAPO/EOG_MATH_CONV_TO_FRACT - Convert Number into Fraction with Max. z-Digit Numerator/Denominator

RFUMSV00 - Advance Return for Tax on Sales/Purchases   General Material Data  
This documentation is copyright by SAP AG.
SAP E-Book

Functionality

A number in fraction or decimal display is converted to a fraction u / v with a maximum numerator and denominator.

Method

A number x is expanded as a regular continued fraction with integer partial quotients A():

                               1
   X = A(0) +  ------------------------------------
                                    1
                A(1) +  ---------------------------
                                        1
                        A(2) +  -------------------

                                           ...

                                     --------------
                                                1
                                     A(n-1) +  ----
                                               A(n)

The continued fraction expansion is terminated when the end of the continued fraction has been reached (X = x) or the newly calculated numerator or denominator can no longer be represented (X is an approximation for x).

In the latter case, the output representation is the best representable number in the form u / v with regard to "mediant rounding".
This means if u / v and u' / v' are two representable numbers next to each other with u / v < x < u' / v', then

- rounding down takes place                    &lt;
- rounding up takes place         if  x  >  (u + u') / (v + v')
- rounding to the smaller denominator takes place  =

Example

The continued fraction expansion of the conversion factor

   FT2      145161
   ---  =  -------  =  0,09290304  =  x
    M2     1562500

with the restriction to a max. 5-character numerator and denominator leads to the finite sequence

   ( 0, 10, 1, 3, 4, 4, 8, 1, 2, 1, 1, 1 )

for the partial quotients A() / after conversion to a proper fraction for the approximation

          7099
   X  =  -----  =  0,09290304005863...
         76413

Notes

  • u and v are always relatively prime, i.e. the representation of the result as a proper fraction is always shortened.
  • Every rational number has a finite continued fraction expansion. If this continued fraction expansion is not terminated, the denominator of the last partial quotient A(n) corresponds to the largest common divisor of numerator and denominator of the original rational number x (Euclidean geometry).
  • Only in the case of data retention (storage) of the quantities as a rational number:
    A pole p can also be included as an optional parameter, so that the condition x + r = p (with remainder r = p - x and r = /SAPAPO/EOG_MATH_CONV_TO_FRACT(r) ) is fulfilled, i.e. all numerators and

    Example:
    A quantity p is split into two parts x and r.

    It can be shown that, in the case of a specified pole p, only the multiples of the denominator of p can fulfill the above condition as candidates for the denominators of x and r.

    As the already existing denominator of p is not included in the continued fraction expansion of x, the approximation must be calculated as follows:
  • For all multiples of the denominator of p, determination of x and r in such a way that the above condition is met.

  • For all approximations, calculation of the relative deviation to the original number x.

  • Shortening of numerator and denominator of best approximation (in contrast to the partial fraction expansion, (u and v are not always relatively prime).

Further information

Knuth, D.E.: The Art of Computer Programming, Volume 2, Seminumerical Algorithms, Second Edition. Reading: Addison-Wesley 1981. pp. 313-315, 339-341, 363 (40. and 43.).

or

Knuth, D.E.: Transl. by R. Loos. Original title: The Art of Computer Programming. Berlin; Heidelberg: Springer 2001. pp. 148-150, 176-180, 200 (40. and 43.).





Parameters

E_DENOM
E_ERROR_ABS
E_ERROR_REL
E_GCD
E_NUMER
E_VALUE
I_DENOM
I_DENOM_POLE
I_FRACT_LENGTH
I_NUMER
I_NUMER_POLE

Exceptions

CONVERSION_OVERFLOW
E_FACTORS_INVALID
E_VALUE_INVALID
I_FACTORS_INVALID
I_POLE_FACTORS_INVALID

Function Group

APO/SAPLEOG_MATH

TXBHW - Original Tax Base Amount in Local Currency   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.

Length: 8354 Date: 20240424 Time: 230411     sap01-206 ( 91 ms )