Re: 4gl math functions
Posted in 1993
>From: uunet!hermes1.sps.mot.com!inf_bb (informix users bb) >Date: Fri, 30 Apr 93 16:39:46 MST >Subject: 4gl math functions >X-Informix-List-Id: <list.2226> >I need to be able to compute cos,sin,sqr,log,etc from within 4gl. I seem >to recall reading in a tech bulletin that 4gl could do these, but I cant >find any documentation for it in the 4gl manuals. > >If these functions are supported, does anyone have a nice set of c routines >that can be linked into the fglgo runner? I don't think you can do it directly in I4GL. The engine you've got (5.00) probably supports them (undocumented, perhaps), so you could do: SELECT cos(0.34567) FROM Systables where tabid = 1; which yields 0.940849 -- it certainly worked on my 5.01.UC1A2 database, which is where I got the answer from. However, that is hardly a good answer, since the SELECT would have to be re-prepared for every value. My understanding is that the engine converts whatever you supply as a value into a C double and passes that to the C maths library and then returns the result. That being the case, you can do the same in I4GL and get the results without doing a round trip to the engine and back. If you need to simulate this, you need a bunch of routines like this: #include <math.h> int fgl_cos(i) int i; { double d; double r = HUGE; if (i == 1) { popdub(&d); r = cos(d); } retdub(&r); return(1); } If you need more precision, you'll need to go get a book on numerical analysis, use the value from cos() as an initial approximation, and then apply some iterative formula (Newton-Raphson?) on the value using decimal arithmetic. It won't be as fast, but how accurate do you need? Yours, Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>