Skip to Content
author's profile photo Former Member
Former Member

MOD operation fail for large numbers

Hi ,

I have 2 large float numbers. I want to perform mathematical mod operation on these 2 numbers but i keep getting a blank value.

Is this because SAP Abap does not handle these large numbers? I used float data type because I figured this data type would be the best to handle large numbers.

data: lv_n type f,

lv_temp type f,

result type f.

lv_temp = 1.1417981541647679E+46.

lv_n = 2.7730000000000000E+03.

RESULT = lv_temp mod lv_n.

Value of variable RESULT should be 1278 or 1.2780000000000000E+03. I keep getting a blank on this statement. (this is the actual mathematical statement that I am trying to achieve via ABAP , 512^17 mod 2773).

Does anyone know why this is happening or if I am doing something wrong or just that SAP ABAP doesn't handle large numbers?

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 27, 2013 at 10:19 AM

    I would say ABAP does not handle large numbers. There is no large enough integer data type for it.

    Even if your code worked, answer won't be precise because of rounding of float data.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 27, 2013 at 10:48 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 27, 2013 at 10:55 AM

    Hi,

    Thank you for your replies. Manish was right SAP ABAP doesn't handle large numbers.

    This is the information from the ABAPDOCU.

    The ABAP runtime environment always calculates commercially and not numerically like the underlying machine arithmetic.

    The ABAP runtime environment always calculates commercially and not numerically like the underlying machine arithmetic. According to the rounding algorithm of the latter, the end digit 5 must always be rounded to the nearest even number (not the next largest number), that is, from 2.5 to 2, 3.5 to 4.

    You should also note that multiplication using powers of 10 (positive or negative) is not an exact operation.

    • For example, although it can be represented exactly in two parts, a floating point number F of value 100.5, after the operation
      F = F / 100 * 100.
      it has the value 100.49999999999999.

    As well as rounding errors, the restricted number of decimal places for the mantissa can lead to the loss of trailing digits.

    • For example, 1 - 1,0000000000000001 results in zero.

    This means you cannot rely on the last digits in floating point arithmetic. In particular, you should not usually test two floating point numbers a and b for equality; instead, you should check whether the relative difference abs((a - b)/a) is less than a predefined limit, such as 10**(-7).

    I was trying to implement the RSA algorithm. Got thru 80% of the way. Now I have to scrap it all. Such a pity.😢😢😔

    Thanks again.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      It can still be done by writing an elaborate code. Not sure how slow that would be.

      Just like people used to handle the then large numbers on 8085 microprocessor.

      For example, C language did not support calculation of factorial of 10^100 (googol), but program have been written to do so.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.