Hi Neelakanta, In SQLite, REAL data type (which is equivalent to double type in C) is used for storing both float and double values. When sqlite3_column_text is used to get float number, it returns a double value with the precision of 15 decimal digits, which is enough to achieve full floating point precision for float data type. To achieve full floating point precision for float data type, it's needed 8 decimal digits.
So, there is no need for workaround for float data type. Best regards, Zoran -----Original Message----- From: Neelakanta Reddy [mailto:reddy.neelaka...@oracle.com] Sent: den 17 april 2014 12:57 To: Zoran Milinkovic Cc: opensaf-devel@lists.sourceforge.net Subject: Re: [PATCH 2 of 2] IMM: fix loading double values from PBE in immload [#53] Hi zoran, The same thing can be done for SA_IMM_ATTR_SAFLOATT , where snprintf(val, size, "%.8g", d); can be used. /Neel. On Tuesday 15 April 2014 08:08 PM, Zoran Milinkovic wrote: > osaf/services/saf/immsv/immloadd/imm_pbe_load.cc | 25 > ++++++++++++++++++----- > 1 files changed, 19 insertions(+), 6 deletions(-) > > > When PBE is being loaded, sqlite3_column_text function is used for fetching > double values. The function returns a string representation of double value > in 15 bytes, which is not enough to preserve full floating point presicision. > > diff --git a/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc > b/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc > --- a/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc > +++ b/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc > @@ -587,12 +587,25 @@ bool loadObjectFromPbe(void* pbeHandle, > std::list<char*> attrValueBuffers; > char *val; > while(rc == SQLITE_ROW) { > - val = (char *)sqlite3_column_text(stmt, 0); > - if(val) { > - /* Guard for NULL values. */ > - char *str = strdup(val); > - attrValueBuffers.push_front(str); > - TRACE("ABT pushed value:%s", str); > + if((*it)->attrValueType == > SA_IMM_ATTR_SADOUBLET) { > + double d = sqlite3_column_double(stmt, > 0); > + /* 30 bytes will be enough large for > storing a double value */ > + val = (char *)malloc(30); > + int size = snprintf(val, 30, "%.17g", > d); > + size++; > + if(size > 30) { > + val = (char *)realloc(val, > size); > + snprintf(val, size, "%.17g", d); > + } > + attrValueBuffers.push_front(val); > + } else { > + val = (char *)sqlite3_column_text(stmt, > 0); > + if(val) { > + /* Guard for NULL values. */ > + char *str = strdup(val); > + > attrValueBuffers.push_front(str); > + TRACE("ABT pushed value:%s", > str); > + } > } > > rc = sqlite3_step(stmt); ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/NeoTech _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel