473,394 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to Define High-precision Date type

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?

Mar 31 '06 #1
15 3965
In article <11**********************@i39g2000cwa.googlegroups .com>,
Donkey <ne********@hotmail.com> wrote:
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.

--
Programming is what happens while you're busy making other plans.
Mar 31 '06 #2
"Donkey" <ne********@hotmail.com> writes:
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).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 31 '06 #3
Donkey wrote:
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.

Mar 31 '06 #4
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.841470984807896506652502321630298999622563060798 37106567275170999191040439123966894863974354305269 5854349
Mar 31 '06 #5
Donkey wrote:
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?


http://www.google.com/search?q=arbitrary+precision

http://en.wikipedia.org/wiki/Arbitra...ion_arithmetic

http://www.mpfr.org/
Mar 31 '06 #6
On Fri, 31 Mar 2006 06:45:30 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthlink.net> wrote:
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
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 31 '06 #7
Mark McIntyre wrote:
On Fri, 31 Mar 2006 06:45:30 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthlink.net> wrote: [...]
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...


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.
Mar 31 '06 #8
On Fri, 31 Mar 2006 22:55:53 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthlink.net> wrote:
Mark McIntyre wrote:
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.


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
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 31 '06 #9
"Mark McIntyre" <ma**********@spamcop.net> wrote in message
news:io********************************@4ax.com...
On Fri, 31 Mar 2006 22:55:53 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthlink.net> wrote:
Mark McIntyre wrote:
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.


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.
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.


I apologize for my ignorance: City==London?
Apr 2 '06 #10
stathis gotsis wrote:
"Mark McIntyre" <ma**********@spamcop.net> wrote in message
news:io********************************@4ax.com...
On Fri, 31 Mar 2006 22:55:53 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthlink.net> wrote:
Mark McIntyre wrote:
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.


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.
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.


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.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Apr 2 '06 #11
On Sun, 2 Apr 2006 03:31:21 +0300, in comp.lang.c , "stathis gotsis"
<st***********@hotmail.com> wrote:
about. I've worked in the City for 15 years now, and I do.


I apologize for my ignorance: City==London?


Yes, the City of London is the actual name of the borough that
comprises the central part of London. It contains the financial and
commerce district, barring a few weirdos who've moved to Docklands.

http://www.cityoflondon.gov.uk/Corpo...undary_map.htm

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 2 '06 #12
Joe Wright <jo********@comcast.net> wrote:
stathis gotsis wrote:
"Mark McIntyre" <ma**********@spamcop.net> wrote in message
news:io********************************@4ax.com...
On Fri, 31 Mar 2006 22:55:53 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthlink.net> wrote:

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.

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.
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.


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
Apr 3 '06 #13
On Mon, 03 Apr 2006 07:00:23 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
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...
> 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.


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
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 3 '06 #14
Mark McIntyre <ma**********@spamcop.net> wrote:
On Mon, 03 Apr 2006 07:00:23 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
> 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.


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....


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
Apr 4 '06 #15
REH

Martin Ambuhl wrote:
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

Apr 4 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Dead RAM | last post by:
Hey people, i'll try to keep this short ;) Here is what I want to type (or at least close too)... #define VER_BUILD 1 #define STR_VER_BUILD "VER_BUILD" But what happends is...
11
by: Jürgen Hochwald | last post by:
Hi Maybe this is a simple question, but I don't know how to solve. Background: A weather station connected to the serial port sends data packets. This data packets are containing variables fom...
31
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there is not standard method to "(...) query the...
16
by: msnews.microsoft.com | last post by:
I am teaching C# to my 11 year old child. One challenge is that all the C# books I own and that I have seen in bookstores are full of language that is not easily comprehended by a student at that...
2
by: #define中的问题 | last post by:
#define RGB(r,g,b)((COLORREF)((BYTE)(r)| \ ((WORD)((BYTE)(g))<<8))| \ ((DWORD)(BYTE)(b))<<16))) what is the "| \" mean above? who give me a answer? Thank you very mauch!
2
by: Jarod | last post by:
Hello I am curious how should I use the array of doubles. The problem is I don't know in advance how much elements would it have, but I can be sure it will be less then let's say 150 or 500. So...
3
by: Lighter | last post by:
Why does Platform SDK define union LARGE_INTEGER in such a way? ntdef.h defines the union LARGE_INTEGER as follows: typedef union _LARGE_INTEGER { struct { ULONG LowPart;
40
by: Chandresh | last post by:
Hi All, I am a graduate student in EE. I have a question that might seem unusual but in my opinion it is interesting and I request all experts to reply. Being a grad student, I came along many...
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
8
by: =?Utf-8?B?dGFuaQ==?= | last post by:
Hello there, one of my servers is running windows 2003 and IIS 6.0. We have big performance issues on that server and I found out that a high CPU usage iniciated by w3wp.exe causes the problem....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.