Re: Documented undocumented functions (was Re: Undocumented math Functions)
Posted in 1994
>From ilist@rmy.emory.edu Wed Jul 27 03:18:08 1994 >From: peter@prospect.anprod.csiro.au (Peter Wiley - Poultry) >Subject: Re: Documented undocumented functions >Date: 27 Jul 1994 01:22:11 GMT >To: informix-list@rmy.emory.edu >X-Informix-List-Id: <news.7821> > >Yes, you can do the transforms form log -> antilog but like you, my math is >somewhat atrophied (putting it politely). > >Fortunately, with LOGN an EXP it isn't necessary. This one fooled me at first >but it looks like select EXP(some_col) gives you e raised to the value. So >no need for an antilog function. I played with converting LOG10 to log_e then >doing this and all appears OK given the inevitable rounding errors with >floating point arithmetic. > >This also enables the construction of a power function not limited to integer >exponents and without adding a C function to the runner. Or cube roots etc. >In fact, pretty much anything you could want. In a previous mail (discussing SQRT), I noted: >This works in 5.0x and later engines. You also have the various >trigonometric and algebraic functions -- COS, SIN, TAN, ATAN, ATAN2, EXP, >LOGN, LOG10, ABS, MOD, POW, ROOT. These are documented in the Version 6.00 >Informix Guide to SQL: Syntax book. I don't think they were documented >previously. The only unusual function in the collection is ROOT; if takes >2 arguments, the value for which you want the Nth root, and the value N >(which can, in fact, be omitted and defaults to 2, giving you the square >root). ROOT(X, N) is equivalent to POW(X, 1/N), in other words. Note >that both ROOT and POW work with fractional exponents. I believe the >implementation is by direct calls to the corresponding C library functions, >using doubles as arguments. Thus, treat the values returned for 32-digit >DECIMALs with a touch of caution; the answer is probably only (!) good for >14 digits or so, which is generally adequate. On top of those, there are also ROUND, TRUNC and SQRT, and I omitted ASIN and ACOS from the list (pure oversight), though someone else mentioned those. >Having to insert into a temp table and then select back is a bit of a >kludge but I can live with this. You don't need to use temporary tables at all. You can use the following code: DATABASE stores5 MAIN DEFINE d1 DECIMAL DEFINE d2 DECIMAL DEFINE d3 DECIMAL LET d1 = 3.14159 / 4 SELECT cos(d1), sin(d1) INTO d2, d3 FROM Systables WHERE tabid = 1 DISPLAY d1, d2, d3 END MAIN This technique of "SELECT stuff FROM Systables WHERE Tabid = 1" works on all Informix databases where you want a single row of data; it can also be used for CURRENT, USER, and TODAY, etc. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>