Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: 1 [2] 3 4 ... 10
 on: December 17, 2019, 10:32:46 am 
Started by Lu?s T. - Last post by Lu?s T.
Thanks Rene and Henry,

Yesterday my colleague Josť Virtuoso found a post in Stack Overflow discussing the theme:

They refer to the same algorithm and also point for an old post with a really deep discussion about efficient implementations of integer based power function:

In the meanwhile we'll use your myExp() function!

 on: December 17, 2019, 10:04:34 am 
Started by Lu?s T. - Last post by Rene S.
s/ a mail Henry / a mail from Henri /
s/ provision / precision /

 on: December 17, 2019, 10:02:03 am 
Started by Lu?s T. - Last post by Rene S.
Hello, I got this morning a mail Henri (thanks again).
See this url:
The 4gl operator ** uses integer exponents. This fit's exactly to the problem of computation of large positive integer powers of a number.

I've adapted exp_by_squaring_iterative to this function:
  1. FUNCTION myExp(x, n)
  2.    DEFINE x DECIMAL(32)
  3.    DEFINE n INT
  4.    DEFINE y DECIMAL(32)
  7.        RETURN NULL
  8.    END IF
  9.    IF n < 0 THEN
  10.        LET x = 1 / x
  11.        LET n = -n
  12.    END IF
  13.    IF n = 0 THEN
  14.        RETURN 1
  15.    END IF
  16.    LET y = 1
  17.    WHILE n > 1
  18.        IF (n MOD 2) == 0 THEN
  19.            LET x = x * x
  20.            LET n = n / 2
  21.        ELSE
  22.            LET y = x * y
  23.            LET x = x * x
  24.            LET n = (n - 1) / 2
  25.        END IF
  26.    END WHILE
  27.    RETURN x * y

The function is fast and uses a provision of 32.
The internal implementation of ** should be adapted as soon as possible

 on: December 17, 2019, 08:29:34 am 
Started by Huy H. - Last post by Rene S.
Hello Reuben,
Yes, I did.
OTH: why adding extra code (setActionActive here and there) if on action infield exists? On action infield has been introduced for exactly this reason: simplify the 4gl code. The runtime controls the activation of actions.

If (hypothetically) the attribute clause would be supported for an on action infield then we end in the dilemma: the programmer must repeat all attributes for each action with the same name. This is the opposite of simple.

 on: December 17, 2019, 04:43:47 am 
Started by Huy H. - Last post by Reuben B.

Did you consider the case of a one-off action where it is preferred to define all you need to with the ON ACTION, and therefore no need to touch a .4ad or .per.  In that case I think ...

  1. ON ACTION foo INFIELD field1 ATTRIBUTES(TEXT="...", IMAGE="...")
would be preferred to

  2.    CALL DIALOG.setActionActive("foo", FALSE)
  3. BEFORE FIELD field1
  4.    CALL DIALOG.setActionActive("foo", TRUE)
  5. AFTER FIELD field1
  6.    CALL DIALOG.setActionActive("foo", FALSE)
  8. ON ACTION foo ATTRIBUTES(TEXT="...", IMAGE="...")


 on: December 16, 2019, 04:37:21 pm 
Started by Lu?s T. - Last post by Rene S.
Opps. Yes, this helps a lot!
Please wait for more details.

 on: December 16, 2019, 04:21:05 pm 
Started by Lu?s T. - Last post by Lu?s T.
Hello Rene,

The expoents, in the situation we analysed, are allways negative and run from 0 to -1460.

This happens when we call IRR (Internar Return on Investment), using Newton method. We need to actualize each cash-flows of a loan to the number of days from the initial date of the loan. As we are calculating this in a dayly base, and the operation have 4 years duration, it makes around  1460 day for the last flow.

In the Newton method we do the calculation several times until we find the right rate. That's why the performance of ** is so relevant.

Hope this helps


 on: December 16, 2019, 03:54:42 pm 
Started by Lu?s T. - Last post by Rene S.
Hello Luis,
for my curiosity/better understanding: what values of the exponent do you use?
Please give an example reproducing the performance factor 100 comparing the operator ** with your c-function. I can't reproduce this with my values.

I made a quick test, comparing the performance with Informix c4gl. When using huge exponents (>16) then Informix is faster. If the exponent is less than 16 then Genero is faster.

 on: December 16, 2019, 02:54:56 pm 
Started by Lu?s T. - Last post by Lu?s T.
Thanks for the answer Rene.

The problem is that, if I call pow(), which is the same than calling the C function we defined, i will loose precision.

We detected the inefficiencies of ** when we migrated our application to Genero. At that moment we substituted ** to the C implementation but we went into a situation where our application didn't work as it worked in Informix 4GL. When we analysed the issue we come to the conclusion the reason was loss of precision. When we rollback to the ** operator, we solved the problem.

I have the idea that the Informix 4GL implementation of ** is quicker than the Genero's one. Don't you have that idea?


 on: December 16, 2019, 02:25:47 pm 
Started by Lu?s T. - Last post by Rene S.
The operator ** calls a decimal implementation of the function power.
Notice: the exponent is an int.
  1. -- read
  2.     a ** b
  3. -- as
  4.    xxx(a, b)
  5. -- where xxx is the

Decimal functions are usually slow compared with the same function using float or double parameters.
Compare the performance of decimal functions with the performance of float or double function before integrating the math coprocessor x87 into the CPU. In those days (before 80486, launched April 1996) those function were implemented by software.

Don't use the operator **.

Use util.Math.pow(x FLOAT, y FLOAT) returning FLOAT


Pages: 1 [2] 3 4 ... 10
Powered by SMF 1.1.21 | SMF © 2015, Simple Machines