Re: Native byte storage format
Posted in 1997
Here's a whole pile of information in more detail than you ever wanted... The relevant section for you is the one you'd find by searching for "Decimal Storage". Although the recycled messages data back to 1991, nothing has changed since then that I know of. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> >From: Sean Birkhead <sean@infosol.ie> >Date: 21 May 1997 10:18:08 +0000 >X-Informix-List-Id: <list.14593> > >I am using Easysoft's ODBC drivers to talk to an Informix database >(standard engine). >The software actually talks to raw CISAM files rather than Informix >and I therefore must define the file format to the ODBC software. > >I have managed to successfully read char variables,integers,serial and >date fields but I am having great trouble with decimals and floats. > >For example an integer must be defined to the application as a >four byte reversed word (Long word reversed). > >Does anybody know how floats and decimals (e.g. decimal 12,2) >are stored by Informix in the raw CISAM FILE? >Even better - has anybody ever done this with Easysoft's ODBC? > >Thanks for any help. >Sean Birkhead. =========================================================================== Date: Tue, 19 Mar 91 19:49:18 GMT From: johnl@obelix (Jonathan Leffler) Subject: Extreme DECIMAL values Dear Everybody, I have always thought that decimals were good for, roughly, the range 1E+128 .. 1E-126. I wrote the program below to produce exponential notation and engineering notation numbers (the engineering notation was just to see what was involved). The program is compiled as: IXD=$INFORMIXDIR cc -I$IXD/incl -O -DTEST decsci.c -o decsci $IXD/lib/libsql.a The output it produces is shown below. It is clear that the nominal range is more nearly: 1.0E-130 <= abs(x) < 1.0E+126 I accept I was wrong on +128/-126; I should have had +126/-128 in mind. But it was a mild surprise to find +126/-130. Where would I have seen the range documented? Has anybody got any comments to offer on this behaviour? Yours sincerely (and non-critically), Jonathan Leffler (johnl@asterix) BTW: if the code below is of use, please feel free to use it. Output: Scientific notation input = 3.14159265358979323844e+00 , ret val = :+3.14159E+00: input = 3.14159265358979323844e+01 , ret val = :+3.14159E+01: input = 3.14159265358979323844e+02 , ret val = :+3.14159E+02: input = 3.14159265358979323844e+03 , ret val = :+3.14159E+03: input = 3.14159265358979323844e+33 , ret val = :+3.14159E+33: input = 3.14159265358979323844e+66 , ret val = :+3.14159E+66: input = 3.14159265358979323844e+99 , ret val = :+3.14159E+99: input = 3.14159265358979323844e+100 , ret val = :+3.14159E+100: input = 9.99999999999999999999e+125 , ret val = :+1.00000E+126: deccvasc error -1200 on 1.00000000000000000000e+126 input = 3.14159265358979323844e+00 , ret val = :+3.14159E+00: input = 3.14159265358979323844e-01 , ret val = :+3.14159E-01: input = 3.14159265358979323844e-02 , ret val = :+3.14159E-02: input = 3.14159265358979323844e-03 , ret val = :+3.14159E-03: input = 3.14159265358979323844e-33 , ret val = :+3.14159E-33: input = 3.14159265358979323844e-66 , ret val = :+3.14159E-66: input = 3.14159265358979323844e-99 , ret val = :+3.14159E-99: input = 3.14159265358979323844e-100 , ret val = :+3.14159E-100: input = 3.14159265358979323844e-126 , ret val = :+3.14159E-126: input = 3.14159265358979323844e-127 , ret val = :+3.14159E-127: input = 1.00000000000000000000e-128 , ret val = :+1.00000E-128: input = 1.00000000000000000000e-129 , ret val = :+1.00000E-129: input = 1.00000000000000000000e-130 , ret val = :+1.00000E-130: deccvasc error -1201 on 9.99999999999999999999e-131 Code (formatted with tabstops set at 4): /* %Z%File: %M% %Z%Version: %I% %Z%Last changed: %E% %Z%Purpose: Exponential formatting of DECIMALs %Z%Author: J Leffler */ #include <decimal.h> #define SIGN(s, p) ((s) ? '-' : ((p) ? '+' : ' ')) #define VALID(n) (((n) <= 0) ? 6 : (((n) > 32) ? 32 : (n))) extern char *dececvt(); static char buffer[41]; /* Big enough for anything */ #ifndef lint static char sccs[] = "%W% %E%"; #endif static char *decexp(dst, dp) register char *dst; register int dp; { *dst++ = 'E'; if (dp >= 0) *dst++ = '+'; else { *dst++ = '-'; dp = -dp; } if (dp / 100 != 0) *dst++ = dp / 100 + '0'; *dst++ = (dp / 10) % 10 + '0'; *dst++ = (dp % 10) + '0'; *dst = '\\0'; return (dst); } char *decsci(d, ndigit, plus) dec_t *d; int ndigit; int plus; { register char *dst = buffer; register char *src; int sn; int dp; ndigit = VALID(ndigit); src = dececvt(d, ndigit, &dp, &sn); *dst++ = SIGN(sn, plus); *dst++ = *src++; *dst++ = '.'; while (*src) *dst++ = *src++; dst = decexp(dst, dp - 1); return (buffer); } #ifdef TEST #include <stdio.h> #include <assert.h> #define DIM(x) (sizeof(x)/sizeof(*(x))) static char *values[] = { "3.14159265358979323844e+00", "3.14159265358979323844e+01", "3.14159265358979323844e+02", "3.14159265358979323844e+03", "3.14159265358979323844e+33", "3.14159265358979323844e+66", "3.14159265358979323844e+99", "3.14159265358979323844e+100", "9.99999999999999999999e+125", "1.00000000000000000000e+126", "3.14159265358979323844e+00", "3.14159265358979323844e-01", "3.14159265358979323844e-02", "3.14159265358979323844e-03", "3.14159265358979323844e-33", "3.14159265358979323844e-66", "3.14159265358979323844e-99", "3.14159265358979323844e-100", "3.14159265358979323844e-126", "3.14159265358979323844e-127", "1.00000000000000000000e-128", "1.00000000000000000000e-129", "1.00000000000000000000e-130", "9.99999999999999999999e-131", }; extern char *dececvt(); main() { char *s; dec_t d; int i; int err; printf("Scientific notation\\n"); for (i = 0; i < DIM(values); i++) { if ((err = deccvasc(values[i], strlen(values[i]), &d)) != 0) printf("deccvasc error %d on %s\\n", err, values[i]); else { s = decsci(&d, 6, 1); printf("input = %-30s, ret val = :%s:\\n", values[i], s); } } exit(0); } #endif =========================================================================== Date: Fri, 22 Mar 91 11:13:25 -0800 From: rbc@grizzly (Dick Curtis) To: johnl@beehive, tech@asterix Subject: Re: More extreme DECIMAL values Please enter the bug, John. In my new role as quality bir