How to Define High-precision Date type

D

Donkey

Hi,
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?
 
W

Walter Roberson

The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?

No, if you want longer precision that is provided by the compiler,
then you either have to program the calculation routines yourself,
or else find a pre-written extended precision library and use it.
 
K

Keith Thompson

Donkey said:
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?

Use a library such as GNU GMP (google it).
 
J

jacob navia

Donkey a écrit :
Hi,
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?

The lcc-win32 compiler offers the qfloat data type with 103 digits
precision and 350 bits
#include <stdio.h>
#include <qfloat.h>
int main(void)
{
qfloat s = sinq(1.0q);
printf("%118.109qf\n",s);
}
Output:
0.841470984807896506652502321630298999622563060798371065672751709991910404391239668948639743543052695854349
 
M

Martin Ambuhl

Donkey said:
Hi,
The precision of built-in date type of C is very low. Even using long
double float type or double float type, we can only use 12 or 16 digits
after the decimal point. What can we do if we want to use
high-precision number such as the number with 50 digits after the
decimal point. Can we define a user date type?

The average distance from the sun to Earth is about 149.598e6 km.
Supose DBL_DIG to be 15. A (1e-15 * sun_to_earth_distance) is about .15 mm.
Be careful is assuming stating that 15 significant digits ("digits after
the decimal point" is meaningless) is "very low". When 15 significant
decimal digits allows expressing the average distance from the sun to
the earth to with 0.15 mm, that is high accuracy, indeed.

The place that greater precision becomes meaningful is in intermendiate
results in some arithmetic operations. You might want higher precision
in, say, matrix inversion. There are several things to say about this:
1) long double *might* be sufficient, or
2) many packages exist for doing arithmetic with greater precision, or
3) you are making a serious mistake.
Point (3) is significant. If I found my problem required values beyond
the capabilities of long doubles (18 significant figures and a range of
1e-4391 to 1e4392 on my implementation), I would seriously consider
whether I had pathologogical data or an algorithm that needed fixing.
 
S

Spoon

M

Mark McIntyre

Be careful is assuming stating that 15 significant digits ("digits after
the decimal point" is meaningless) is "very low". When 15 significant
decimal digits allows expressing the average distance from the sun to
the earth to with 0.15 mm, that is high accuracy, indeed.

OTOH, when buying a couple of tonnes of Platinum in Tunisian Dinar,
its easy to rapidly lose all 15 digits, and the discrepancy is quite
expensive... :)
The place that greater precision becomes meaningful is in intermendiate
results in some arithmetic operations.

This is absolutely true.
If I found my problem required values beyond
the capabilities of long doubles (18 significant figures and a range of
1e-4391 to 1e4392 on my implementation), I would seriously consider
whether I had pathologogical data or an algorithm that needed fixing.

Or you work in astronomy or finance...


Mark McIntyre
 
M

Martin Ambuhl

Mark said:
On Fri, 31 Mar 2006 06:45:30 GMT, in comp.lang.c , Martin Ambuhl
Or you work in astronomy or finance...

Nonsense. Astronomers are often ecstatic with data of much less
significance than is guaranteed even for a float. Consider that the
relative error for G, the Newtonian gravitational constant, is 1.5e-4 in
the 2002 CODATA values. Astronomy is an extremely poorly chosen example
for your purposes.

Nonsense. No sane person is using floating point types for finance, in
the first place. Such a person will be fired before the day is out,
anyway, so the number of significant digits is irrelevant.

Let's assume a less than sane person did use long doubles of my
implementation for finance. It is unlikely that such a person would
deal in numbers larger than those for the United States government. The
estimated revenues for 2011 (the largest numbers available) are
$3.034861e12 ($2.233286e12 on budget) and estimated expenditures are
$3.23879e12 ($2.648669e12 on budget). These numbers are all expressible
to the penny in 15 decimal digits. They would need to be 1000 times as
large to cause concern with 18 significant digits. Of course, the Bush
experience has taught us that these numbers might not even have one
significant digit. Finance is an extremely poorly chose example for
your purposes.
 
M

Mark McIntyre

Mark McIntyre wrote:

Nonsense. Astronomers are often ecstatic with data of much less
significance than is guaranteed even for a float.

Oh, sure. Apparently you don't do much spectroscopy or
astronavigation.
Consider that the
relative error for G, the Newtonian gravitational constant, is 1.5e-4 in
the 2002 CODATA values.

This is a /physically observed/ constant. Its by definition not
accurate.
Astronomy is an extremely poorly chosen example
for your purposes.

Apparently you're not an astronomer.
Nonsense. No sane person is using floating point types for finance, in
the first place. Such a person will be fired before the day is out,
anyway, so the number of significant digits is irrelevant.

Go tell that to the thousands of people using it every single day in
the City, New York .Tokyo, Frankfurt. etc.

Sorry, but you really have absolutely no idea what you're talking
about. I've worked in the City for 15 years now, and I do.
It is unlikely that such a person would
deal in numbers larger than those for the United States government.

Rolls on the floor laughing. A few words to play with: leverage,
options, exchange rates. Do you have any idea the total value of FX
and FX options traded last year?
Finance is an extremely poorly chose example for your purposes.

Actually, since I was pointing out that often 15sf isn't enough
precision, I think its a very good example.

Mark McIntyre
 
S

stathis gotsis

Mark McIntyre said:
This is a /physically observed/ constant. Its by definition not
accurate.

Well, many physical constants are meausred through experiments. I think the
relatively low accuracy in the measurement of the gravitational constant is
due to the fact that gravitational forces are rather weak.
Apparently you're not an astronomer.


Go tell that to the thousands of people using it every single day in
the City, New York .Tokyo, Frankfurt. etc.

Sorry, but you really have absolutely no idea what you're talking
about. I've worked in the City for 15 years now, and I do.

I apologize for my ignorance: City==London?
 
J

Joe Wright

stathis said:
Well, many physical constants are meausred through experiments. I think the
relatively low accuracy in the measurement of the gravitational constant is
due to the fact that gravitational forces are rather weak.


I apologize for my ignorance: City==London?

Not exactly. The City is part of London, where the banks are. Piccadilly
and Hyde Park are also parts of London but are not The City.
 
R

Richard Bos

He said _sane_ people. Given the position of economy on the scientific
ladder (basically that of an amputated walrus trying desperately to
climb up, but too stupid and ungainly to find the first rung), it
shouldn't surprise anyone that major financial centres run on what is
basically guesswork. Scare, perhaps, but not surprise.
Not exactly. The City is part of London, where the banks are. Piccadilly
and Hyde Park are also parts of London but are not The City.

Not officially. The City is London, also known as the Square Mile (which
is more or less accurate). Piccadilly is Westminster, and so is Hyde
Park. What you're thinking of is Greater London.

Richard
 
M

Mark McIntyre

On Mon, 03 Apr 2006 07:00:23 GMT, in comp.lang.c ,
He said _sane_ people.

Sorry, I missed that bit. The wall sign was actually invented by us
city types I think. :)
shouldn't surprise anyone that major financial centres run on what is
basically guesswork.

Options pricing, anyone?
Scare, perhaps, but not surprise.

And most of it runs on Windows desktops.....
you can run, but you cant' hide...
Not officially. The City is London, also known as the Square Mile (which
is more or less accurate). Piccadilly is Westminster, and so is Hyde
Park. What you're thinking of is Greater London.

Yer all wrong. The City Of London is an entire city all of its own,
surrounded by more plebeian regions such as Islington, Westminster,
Southwark etc....
Mark McIntyre
 
R

Richard Bos

Mark McIntyre said:
On Mon, 03 Apr 2006 07:00:23 GMT, in comp.lang.c ,


Yer all wrong. The City Of London is an entire city all of its own,
surrounded by more plebeian regions such as Islington, Westminster,
Southwark etc....

That's what I said, innit? Although I wouldn't describe Westmonasterium
as plebeian. Upstart, perhaps.

Of course, all poor saps who _work_ in the City actually come from the
borough to the North-East...

Richard
 
R

REH

Martin said:
When 15 significant
decimal digits allows expressing the average distance from the sun to
the earth to with 0.15 mm, that is high accuracy, indeed.

Just a nit:

I believe you mean high precision, not accuracy. One could say the
distance from the earth to the sun is 0.123456789 meters which is
(relatively) very precise, but not accurate.

REH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top