473,609 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

floating point precision problem

hi,
i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(up to 80 digits)

is it possible ?

does gcc/g++ compiler can give such type of high precision??

plz GIVE A SMALL CODE HOW CAN I ACHIEVE THAT ? which way, i have to
write the code??
Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.
Nov 14 '05 #1
21 12674

"syntax" <sa*****@yahoo. com.hk> wrote in message
news:5c******** *************** ***@posting.goo gle.com...
hi,
i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(up to 80 digits)

is it possible ?

does gcc/g++ compiler can give such type of high precision??

plz GIVE A SMALL CODE HOW CAN I ACHIEVE THAT ? which way, i have to
write the code??
Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.


Use lcc-win32.
For instance:
#include <qfloat.h>
int main(void)
{
qfloat p = 2;
printf("%1.80qf \n",sqrt(p));
return 0;
}
will produce:
1.4142135623730 950488016887242 096980785696718 753769480731766 7973799073
247846210704
Qfloats have a precision of 350 bits, approx 100 digits.

http://www.cs.virginia.edu/~lcc-win32
Nov 14 '05 #2
syntax wrote:

hi,
i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(up to 80 digits)

is it possible ?

does gcc/g++ compiler can give such type of high precision??

plz GIVE A SMALL CODE HOW CAN I ACHIEVE THAT ? which way, i have to
write the code??

Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.


As noted previously in this group, several high-precision libraries in
standard C have been written and are available for download.

A Google search of "high precision arithmetic in C" yields

http://crd.lbl.gov/~dhbailey/mpdist/mpdist.html

among about 126,000 hits.

--
Julian V. Noble
Professor Emeritus of Physics
jv*@lessspamfor mother.virginia .edu
^^^^^^^^^^^^^^^ ^^^
http://galileo.phys.virginia.edu/~jvn/

"God is not willing to do everything, and thereby take away our free wiil
and that share of glory that rightfully belongs to ourselves."
-- N. Machiavelli, "The Prince".
Nov 14 '05 #3
"syntax" <sa*****@yahoo. com.hk> wrote in message

i need to get high presion float numbers.

Generally C compilers will restrict themselves to types supported in
hardware, which are usually 32, 64 and sometimes 80 bits.
If the hardware has high-precison doubles, such as 128 bits, the compiler is
likely to provide an extension such as long long double. However such
hardware is not in common use.

A double is enough precision for almost all uses. If you need more precision
you need to emulate floating point in software (libraries are available to
do just that).
If you want to calculate PI to great precison, there are better algorithms
available that don't rely on arbitrary-precison floating point arithmetic.
Nov 14 '05 #4
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote in message
news:bv******** **@newsg1.svr.p ol.co.uk...
"syntax" <sa*****@yahoo. com.hk> wrote in message

i need to get high presion float numbers.
Generally C compilers will restrict themselves to types supported in
hardware, which are usually 32, 64 and sometimes 80 bits.
If the hardware has high-precison doubles, such as 128 bits, the compiler

is likely to provide an extension such as long long double. However such
hardware is not in common use.


Sun Sparcs are in pretty common use. They have 128-bit floating-point
format. And every compiler I know calls it long double.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 14 '05 #5
syntax wrote:
hi,
i need to get high presion float numbers.
Could you give some background about what you need these for? Chances
are, your reasons for wanting this are not sound.
say, i need pi = 22/7.0 = 3.142857....(up to 80 digits)

is it possible ?
Yes, but not in standard C using any compiler I am aware of.
does gcc/g++ compiler can give such type of high precision??
C (and C++) compilers provide floating-point types that generally map
onto types supported by the hardware, so you should not be asking about
a particular compiler, but about a particular hardware platform.

I do not know any hardware platform that supports over 128 bits of
precision for floating point values.
plz GIVE A SMALL CODE HOW CAN I ACHIEVE THAT ? which way, i have to
write the code??
PLEASE DON'T SHOUT. Thank you.

In standard C, you can't. You might want to look at add-on libraries
(e.g., GMP, the GNU Multi-Precision Library). Or perhaps you don't even
want C ("bc" is nice for small high-precision numerical algorithms).
Question2: AT most how much precision can gcc/g++ AND VC++ Give?
Depends on the hardware. Usual sizes for floating point types are 32,
64, 80, and 128 bits. This is a long way short of the 80 digits you
claim you need.
can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.


No.

Best regards,

Sidney

Nov 14 '05 #6
sa*****@yahoo.c om.hk (syntax) writes:
hi,
i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(up to 80 digits)

is it possible ?
<OT>
I hope you're aware that 22/7.0, however precisely you compute it, is
not a very accurate representation of the mathematical constant pi.
22/7.0 is 3.(142857)* (that's a repeating decimal, 3.142857142857. ..);
pi is 3.1415926535... . (The notation for a repeating decimal is
something I just made up.)
</OT>
Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.


There are only three predefined floating-point types in standard C:
float, double, and long double. A compiler could provide, say,
"long long double" as an extension, but I don't know of any system
with direct hardware support for more than three sizes. Another
poster mentioned a "qfloat" type provided by one particular compiler,
but of course that's non-portable (which isn't necessarily a reason
not to use it).

If you want a more portable solution, there are a number of
extended-precision numeric libraries floating (sic) around. Probably
the best known is gmp, the GNU MP library, available from gnu.org.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #7
On Fri, 30 Jan 2004 20:32:00 GMT, in comp.lang.c , "P.J. Plauger"
<pj*@dinkumware .com> wrote:
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote in message
news:bv******* ***@newsg1.svr. pol.co.uk...
If the hardware has high-precison doubles, such as 128 bits, the compiler is
likely to provide an extension such as long long double. However such
hardware is not in common use.
Sun Sparcs are in pretty common use.


for some definitions of common !
I've not seen too many of them in kids bedrooms, internet cafes, etc.
They have 128-bit floating-point
format. And every compiler I know calls it long double.


Doesn't intel have a similar longish double? Hardware specific
question of course, offtopic here.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #8
Keith Thompson wrote:
sa*****@yahoo.c om.hk (syntax) writes:

i need to get high presion float numbers.
say, i need pi = 22/7.0 = 3.142857....(up to 80 digits)
is it possible ?


<OT>
I hope you're aware that 22/7.0, however precisely you compute it, is
not a very accurate representation of the mathematical constant pi.
22/7.0 is 3.(142857)* (that's a repeating decimal, 3.142857142857. ..);
pi is 3.1415926535... . (The notation for a repeating decimal is
something I just made up.)
</OT>


No it isn't (just made up). AGMTA. However pi is not a repeating
decimal :-) Some of the best rational approximations I know for
pi are:

22 / 7
355 / 113
833719 / 265381
1146408 / 364913
4272943 / 1360120
5419351 / 1725033
63885804 / 20335483
74724506 / 23785549
80132847 / 25510582

with the error decreasing by about a factor of 4 or more for
those. They assume a correct value is 3.1414926535897 93.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #9
thanks jacob navia

win lcc-win32 is working....

some of you are suggesting to use GMP library. i dont know even
whetehr my compiler has that library..my compiler is gcc/g++ 2.98
version.

in order to see whether GMP is there
i simply wrote $ ls /usr/lib/
and i found something like this (along with other libraries)

libgmp.a libgmp.so
libgmp.so.3
libgmp.so.3.1.1

do you think my compiler has GMP support?

if so can you plz give me code to calculate sqrt(2) upto 80
digits??.. so that i am be convinced that my GMP library works well.

i am working through telnet..Red Hat linux.7.0.1
does Higher version of linux( Red hat linux 9 ) supports GMP library
in-built??


Keith Thompson <ks***@mib.or g> wrote in message news:<ln******* *****@nuthaus.m ib.org>...
sa*****@yahoo.c om.hk (syntax) writes:
hi,
i need to get high presion float numbers.

say, i need pi = 22/7.0 = 3.142857....(up to 80 digits)

is it possible ?


<OT>
I hope you're aware that 22/7.0, however precisely you compute it, is
not a very accurate representation of the mathematical constant pi.
22/7.0 is 3.(142857)* (that's a repeating decimal, 3.142857142857. ..);
pi is 3.1415926535... . (The notation for a repeating decimal is
something I just made up.)
</OT>
Question2: AT most how much precision can gcc/g++ AND VC++ Give?

can i write

double double double double x = 22/7.0 ? ... so that it could hold
highly precise result.


There are only three predefined floating-point types in standard C:
float, double, and long double. A compiler could provide, say,
"long long double" as an extension, but I don't know of any system
with direct hardware support for more than three sizes. Another
poster mentioned a "qfloat" type provided by one particular compiler,
but of course that's non-portable (which isn't necessarily a reason
not to use it).

If you want a more portable solution, there are a number of
extended-precision numeric libraries floating (sic) around. Probably
the best known is gmp, the GNU MP library, available from gnu.org.

Nov 14 '05 #10

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

Similar topics

4
3299
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can interact with a rich 3D environment. Seem to be 90% of the way there! My problems are related to calculations where the result tends to zero (or another defined limit.) Have loads of cases where this kind of interaction occurs but this one
5
3734
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are using the Debug-Version of the program, but it fails (or leads to false results) if we are using the Release-Version. After a long debugging session we found out, that our program was working correctly, but the floating point processing...
687
23261
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is basically the same. in C there arent the simplest things present like constants, each struct and enum...
24
2226
by: j0mbolar | last post by:
C supports single precision floating point and double precision floating point but does it support fixed floating point? i've read that fixed floating point is more accurate than single precision floating point when dealing with dollars and cents.
1
3867
by: Shreyas Kulkarni | last post by:
hi there, recently i have got a problem regarding calculation of sum of digits in a floating point or precision number. the weird behaviour of compiler/language is preventing me from calculating the sum of all digits. the compiler doesnt store the number as given by the user. some of the precision digits are lost or changed (at will!). so by any method, i m unable to reliably calculate the sum of provided number; except i input the...
5
2407
by: Steffen | last post by:
Hi, is it possible to have two fractions, which (mathematically) have the order a/b < c/d (a,b,c,d integers), but when (correctly) converted into floating point representation just have the opposite order? The idea is that the two fractions are almost identical and that the error introduced by going to floating point representation is bigger than the exact difference, but different for the two fractions such that it somehow turns...
15
3914
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this the EPSILON? I know in float.h a FLT_EPSILON is defined to be 10^-5. Does this mean that the computer cannot distinguish between 2 numbers that differ by less than this epsilon?
10
18753
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
137
6635
by: mathieu.dutour | last post by:
Dear all, I want to do multiprecision floating point, i.e. I want to go beyond single precision, double precision and have quadruple precision, octuple precision and the like, and possibly with high speed. What would be the possible alternatives? Thanks for any help
39
3549
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody out there understands what happens. Essentially, when I subtract the (double) function value GRID_POINT(2) from a variable which has been assigned the same value before this gives a non-zero result and I really do not understand why.
0
8067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8567
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...
1
8215
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6993
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...
0
5509
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4015
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
4076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2529
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
0
1380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.