ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

MI instructions for decimal operations

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MI instructions for decimal operations

    Hello! Tell me, are there MI instructions for performing operations on numbers in decimal format? These instructions are intended to be used from a C program.

  • #2
    Can you explain why you would want to use MI functions for this? I would typically use the ILE C built-in support for packed decimal format

    Comment


    • #3
      Yes, Scott, I can explain. The thing is, I actually need to work with decimal from a C++ program, not C. The _DecimalT class template, located in bcd.h, of course provides the full functionality for working with decimal. However, compared to C and RPG, operations with it are about 10 times slower (it measures the speed of a division operation). So I thought that you can write your own class to work with decimal, but use MI instructions to perform operations, and not call __pdiv and other similar functions, as is done in the _DecimalT template.

      Comment


      • #4
        You can use the decimal functions in decimal.h in a C++ program.
        Code:
        #include <iostream>
        #include <decimal.h>
        
        int main()
        {
           decimal(15,5) x;
           x = 5;
           x += .2;
           std::cout << x;
           return 0;
        }

        Comment


        • d7d1cd_
          d7d1cd_ commented
          Editing a comment
          Barbara, I know you can do that. However, the code you show will still use the _DecimalT template instead of the C built-in type decimal(x,y). Accordingly, I will end up with the same performance issue that created this discussion.

      • #5
        I see.

        Unfortunately, I'm not aware of a way to use MI functions. Maybe you could write a set of C or RPG functions, then wrap those with a C++ class? Just a thought.

        Aside from that, I'm not sure what to suggest.

        Comment


        • d7d1cd_
          d7d1cd_ commented
          Editing a comment
          It would be great to use C++ wrappers over C or RPG functions. But the problem is that the concrete type decimal is a compile time property. And since I am writing a library in C++ and it is not known in advance which specific type of decimal the user wants to use, then using the wrapper looks impossible for me.

      • #6
        Among the MI instructions are those that are designed to work with numbers, such as division. However, it is not clear how to use them from a C++ program (or even from a C or RPG). Now, if it were possible to write wrapper functions for these instructions... Is it possible?

        Comment


        • #7
          Unfortunately, you can only use the ones that offer "bound program access" from an ILE program. For example, GENUUID's documentation shows "Bound Program Access", but division does not. So you can only use division from an actual MI program.

          Comment


          • #8
            Originally posted by Scott Klement View Post
            So you can only use division from an actual MI program.
            That is, you need to write a separate MI program and call it to perform the division? Can I ask for a link to an example of a simple MI program?

            Comment


            • #9
              It has been a very, very, very long time since I've written an MI program -- it may have changed completely since then. But, I see there is an example in IBM Docs
              This example shows how to write a simple MI program that receives two packed-decimal parameters and returns the larger value through a third parameter.

              Comment

              Working...
              X