Re: [sqlite] How to input a double num?

2009-10-30 Thread Kees Nuyt
On Fri, 30 Oct 2009 02:47:37 -0700 (PDT), liubin liu
<7101...@sina.com> wrote:

> Thank you!
>
> I mayn't need the high precision like
> "212345678901234567890123456.988290112".


Indeed, you don't. In a previous message you said:

>> The project is on power-measurement. So there
>> are some big nums with high precision. 

I know of no power-measurement with such high precision.
6 or 7 significant digits is the best you can get in that
field. As in "2123456.0"

That a huge accuracy, think of one dollar on a few million.
-- 
  (  Kees Nuyt
  )
c[_]
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-30 Thread liubin liu

Thank you!

I mayn't need the high precision like
"212345678901234567890123456.988290112".



John Crenshaw-2 wrote:
> 
>> May I use sqlite3_bind_double() and sqlite3_prepare_v2() to solve the
>> problem.
> 
> That won't fix it. Your number is too large to fit in any native data
> type. Even the plain math inside your own program won't work right,
> because the precision of the number is limited at the C level, not the
> SQLite or printf level.
> 
> You'll need an arbitrary precision math library, sqlite3_bind_blob(),
> and sqlite3_prepare_v2(). You can't use sqlite3_bind_double() because
> your number is too big for a double.
> 
> FYI, those arbitrary precision libraries are brutes, so brace yourself.
> 
> John
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> 

-- 
View this message in context: 
http://old.nabble.com/How-to-input-a-double-num--tp26105457p26127343.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-30 Thread John Crenshaw
> May I use sqlite3_bind_double() and sqlite3_prepare_v2() to solve the
> problem.

That won't fix it. Your number is too large to fit in any native data
type. Even the plain math inside your own program won't work right,
because the precision of the number is limited at the C level, not the
SQLite or printf level.

You'll need an arbitrary precision math library, sqlite3_bind_blob(),
and sqlite3_prepare_v2(). You can't use sqlite3_bind_double() because
your number is too big for a double.

FYI, those arbitrary precision libraries are brutes, so brace yourself.

John
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-29 Thread liubin liu

Thanks a lot for every reply.

The num is just random num. The project is on power-measurement. So there
are some big nums with high precision.

May I use sqlite3_bind_double() and sqlite3_prepare_v2() to solve the
problem.




liubin liu wrote:
> 
> Now I use the sqlite3_mprintf() and the "%f" to get the double num. My
> code is below.
> 
> Now there is a num like "212345678901234567890123456.988290112". With the
> way of "sqlite3_mprintf()" and "%f", the num is cut to
> "2123456789012346000.00".
> 
> 
> How to input the num "212345678901234567890123456.988290112"?
> 
> 
> code_
> 
> ...
> char *query_format = "INSERT OR REPLACE INTO pow_value_st (id, valid,
> powervalue_1, powervalue_2) VALUES (%d, %d, %f, %f)";
> char *query_string = NULL;
> query_string = sqlite3_mprintf (query_format, index, tc->valid,
> tc->powervalue[0], tc->powervalue[1]);
> printf ("%s\n", query_string); 
> ...
> 
> 
> 
> PS:
> the columns of powervalue_1 and powervalue_2 are defined as DOUBLE type:
> CREATE TABLE pow_value_st (id INTEGER PRIMARY KEY, valid CHAR(1),
> powervalue_1 DOUBLE, powervalue_2 DOUBLE );
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-input-a-double-num--tp26105457p26123863.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-29 Thread John Crenshaw
> He's probably measuring the number of atoms in a city or something.

LOL. Actually my bet is that field of the project has more to do with
number theory. That's the only likely way to get a number that large
with such high precision.

John
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-29 Thread Simon Slavin

On 29 Oct 2009, at 12:38pm, Griggs, Donald wrote:

> Regarding:  How to input the num
> "212345678901234567890123456.988290112"?
>
>
> Purely curious, if it's not confidential -- how are you acquiring
> numbers of such precision?
>
> If these are measurements, I'm just awed by the precision the device  
> is
> achieving.

The number of atoms in our planet is around 10^50.  So with 34 digits  
of accuracy that number is discussing something which has a volume  
which is around one 10^5th the radius of our planet.  He's probably  
measuring the number of atoms in a city or something.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-29 Thread Griggs, Donald
Regarding:  How to input the num
"212345678901234567890123456.988290112"?


Purely curious, if it's not confidential -- how are you acquiring
numbers of such precision?  

If these are measurements, I'm just awed by the precision the device is
achieving.  If instead these numbers represent something other than a
measurement, you might want to consider storing them in a different
form.

Donald Griggs
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-29 Thread Igor Conom
You cannot store 212345678901234567890123456.988290112 using IEEE a 8 byte 
double precision. You cannot do this even with a 16 byte (long double - which 
for x86 architectures is actually 80-bit extended precision - only 64 bit for 
mantissa; is not the quadruple precision).

If you care about precision, then don't use regular floating point operations, 
use a library implementing arbitrary precision operations (ex. 
http://gmplib.org/). You can then store the numbers as blobs. If you need to 
use these columns in expressions for queries ... well, is not straightforward, 
but it can be done with sqlite. Of course, it won't be as efficient. Or you can 
store them as strings and do some tricks.

On the other hand, I see that these columns are named powervalue_1 and 2, 
suggesting that they are the result of some form of pow - you can store then 
the arguments for pow, if this fit your needs..

I'm curious, how did you get the number 212345678901234567890123456.988290112 ?

-ic

--- On Wed, 10/28/09, liubin liu <7101...@sina.com> wrote:

> From: liubin liu <7101...@sina.com>
> Subject: [sqlite]  How to input a double num?
> To: sqlite-users@sqlite.org
> Date: Wednesday, October 28, 2009, 9:48 PM
> 
> Now I use the sqlite3_mprintf() and the "%f" to get the
> double num. My code
> is below.
> 
> Now there is a num like
> "212345678901234567890123456.988290112". With the
> way of "sqlite3_mprintf()" and "%f", the num is cut to
> "2123456789012346000.00".
> 
> 
> How to input the num
> "212345678901234567890123456.988290112"?
> 
> 
> code_
> 
> ...
>     char *query_format = "INSERT OR REPLACE INTO
> pow_value_st (id, valid,
> powervalue_1, powervalue_2) VALUES (%d, %d, %f, %f)";
>     char *query_string = NULL;
>     query_string = sqlite3_mprintf (query_format,
> index, tc->valid,
> tc->powervalue[0], tc->powervalue[1]);
>     printf ("%s\n", query_string); 
> ...
> 
> -- 
> View this message in context: 
> http://www.nabble.com/How-to-input-a-double-num--tp26105457p26105457.html
> Sent from the SQLite mailing list archive at Nabble.com.
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 


  

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-28 Thread Igor Tandetnik
liubin liu wrote:
> Now I use the sqlite3_mprintf() and the "%f" to get the double num. My code
> is below.
> 
> Now there is a num like "212345678901234567890123456.988290112". With the
> way of "sqlite3_mprintf()" and "%f", the num is cut to
> "2123456789012346000.00".
> 
> 
> How to input the num "212345678901234567890123456.988290112"?

double has 53 bits to represent the mantissa. This is good for 15-16 decimal 
digits, which is what you see. You can't possibly hope to accurately represent 
36 significant digits in a double - even at 3 bits per digit, that would 
require at least 14 bytes, and double is only 8 bytes large.

See also http://dlc.sun.com/pdf/800-7895/800-7895.pdf

Igor Tandetnik


___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-28 Thread Dan Bishop
liubin liu wrote:
> Now I use the sqlite3_mprintf() and the "%f" to get the double num. My code
> is below.
>
> Now there is a num like "212345678901234567890123456.988290112". With the
> way of "sqlite3_mprintf()" and "%f", the num is cut to
> "2123456789012346000.00".
>
>
> How to input the num "212345678901234567890123456.988290112"?
You can't.  A double only has 53 bits (about 16 decimal digits) of 
precision.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to input a double num?

2009-10-28 Thread John Crenshaw
Bad plan. Use prepared statements and bind. Otherwise you're going to
create SQL injection vulnerabilities. Prepared statements are faster and
easier to read anyway.

John

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of liubin liu
Sent: Wednesday, October 28, 2009 10:49 PM
To: sqlite-users@sqlite.org
Subject: [sqlite] How to input a double num?


Now I use the sqlite3_mprintf() and the "%f" to get the double num. My
code
is below.

Now there is a num like "212345678901234567890123456.988290112". With
the
way of "sqlite3_mprintf()" and "%f", the num is cut to
"2123456789012346000.00".


How to input the num "212345678901234567890123456.988290112"?


code_

...
char *query_format = "INSERT OR REPLACE INTO pow_value_st (id,
valid,
powervalue_1, powervalue_2) VALUES (%d, %d, %f, %f)";
char *query_string = NULL;
query_string = sqlite3_mprintf (query_format, index, tc->valid,
tc->powervalue[0], tc->powervalue[1]);
printf ("%s\n", query_string); 
...

-- 
View this message in context:
http://www.nabble.com/How-to-input-a-double-num--tp26105457p26105457.htm
l
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] How to input a double num?

2009-10-28 Thread liubin liu

Now I use the sqlite3_mprintf() and the "%f" to get the double num. My code
is below.

Now there is a num like "212345678901234567890123456.988290112". With the
way of "sqlite3_mprintf()" and "%f", the num is cut to
"2123456789012346000.00".


How to input the num "212345678901234567890123456.988290112"?


code_

...
char *query_format = "INSERT OR REPLACE INTO pow_value_st (id, valid,
powervalue_1, powervalue_2) VALUES (%d, %d, %f, %f)";
char *query_string = NULL;
query_string = sqlite3_mprintf (query_format, index, tc->valid,
tc->powervalue[0], tc->powervalue[1]);
printf ("%s\n", query_string); 
...

-- 
View this message in context: 
http://www.nabble.com/How-to-input-a-double-num--tp26105457p26105457.html
Sent from the SQLite mailing list archive at Nabble.com.

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users