473,769 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3999
In article <11************ **********@i39g 2000cwa.googleg roups.com>,
Donkey <ne********@hot mail.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********@hot mail.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_Keit h) 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_di stance) 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.10 9qf\n",s);
}
Output:
0.8414709848078 965066525023216 302989996225630 607983710656727 517099919104043 912396689486397 435430526958543 49
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*****@earthl ink.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*****@earthl ink.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*****@earthl ink.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**********@s pamcop.net> wrote in message
news:io******** *************** *********@4ax.c om...
On Fri, 31 Mar 2006 22:55:53 GMT, in comp.lang.c , Martin Ambuhl
<ma*****@earthl ink.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

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

Similar topics

20
2836
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 the preprocessor see the quots in STR_VER_BUILD and replaces that text with "VER_BUILD"... I need it to see the VER_BUILD and replace it with 1, and only after doing
11
3654
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 one byte up to 4 byted in mixed order. Now I want to define a structure to overlay it with UNION over the receive buffer for easily access to the single values in the data packet. The problem is, that I cannot defind a variable, which only...
31
3742
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 malloc package to find out how big an allocated block is". ( Question 7.27) Is there somwhere explained why - because it would seem to me, that free()
16
4378
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 age. Can anyone recommend books (or perhaps websites) tuned for younger audiences? BTW, its amazing how fast a student can absorb this kind of information at that age. Lucky them! Thanks, Bruce
2
1269
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
2780
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 should I define the largest one or use an arraylist ? I don't resize it, because after a few calculation the application will be closed. It works like that : read the file, make calculations, save the file , close. I could count the rows in a file...
3
8798
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
18109
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 programming languages like Assembly, C, C++, VHDL, Matlab, Perl etc. and I dont remember how I learned them. I am more comfortable with Assembly programming than others. The question is how do you measure proficiency in C and C++ ? It is important...
6
27887
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
26778
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. I couldn't find out what to do on the server itself. I think it must be the application runnig on IIS. Could a MVP please confirm that this is mostly something that i caused by an application. So that I can give it back to our developers. Thanks
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.