473,883 Members | 1,787 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
21 12697

"Mark McIntyre" <ma**********@s pamcop.net> wrote in message
news:29******** *************** *********@4ax.c om...
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.

Itanium supports a possible 128-bit long double IEEE format by combinations
of operations. The native long double supported by single
add/subtract/multiply operations (no divide) is 80 bits, as stored in
memory, plus 2 bits in register to protect against range overflow. As
measured by sizeof, the 80 bit long double may take up 128 bits in memory,
when padded for proper address alignment.
Some people claim that the parallel data types (4 floats or 2 doubles)
constitute a 128-bit type when thinking of AMD, but not when thinking of
Intel, where they came from.
Nov 14 '05 #11
"CBFalconer " <cb********@yah oo.com> wrote in message
news:40******** *******@yahoo.c om...

... They assume a correct value is 3.1414926535897 93.

^
"Oops."
- Oliver Wendell Jones, Bloom County

--
Peter
Nov 14 '05 #12
CBFalconer <cb********@yah oo.com> writes:
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.


"AGMTA"?
However pi is not a repeating decimal :-)


Right, but the OP said that pi = 22/7.0, so maybe he's not talking
about the usual mathematical constant.

--
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 #13
Please don't top-post. The convention here is to write your response
following any quoted text, and to delete anything not relevant to your
response.

A: Because it makes it more difficult to follow the discussion.
Q: Why is top-posting bad?

sa*****@yahoo.c om.hk (syntax) writes:
Keith Thompson <ks***@mib.or g> wrote in message
news:<ln******* *****@nuthaus.m ib.org>... [...]
extended-precision numeric libraries floating (sic) around. Probably
the best known is gmp, the GNU MP library, available from gnu.org.

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.

[...] do you think my compiler has GMP support?


Probably, but the question isn't topical here, since it really isn't a
question about the C programming language. (Incidentally, gmp is a
library, so it isn't tied to the compiler; even if you don't have it,
you can download it, install it, and use it with your compiler;
instructions for doing so are also off-topic.)

If your system has gmp, it probably has documentation for it.

<OT>Try "info gmp".</OT>

--
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 #14
sa*****@yahoo.c om.hk (syntax) wrote in message news:<5c******* *************** ****@posting.go ogle.com>...
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?
Yes. But this is getting out of the realms of being a C question.

#include <gmp.h>

compile with gcc -lgmp

read the manual
http://www.swox.com/gmp/manual/

try it, and direct questions to gm*********@swo x.com


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 #15

"syntax" <sa*****@yahoo. com.hk> wrote in message

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'll tell you how to do it (the accepted method is a bit more sophisticated
than this, but this will work and you can understand it.

Have two floating-point variables, low, set to zero, and high, set to 2.0.
Obviously the square root of two must be between them.

Let's make a guess - halfway between (ie 1.0). Test by multiplying 1.0 by
1.0, and you will get the answer 1.0. This is below 2, so set low to 1.0.
Now make another guess - 1.5. 1.5 * 1.5 is above 2.0, so set high to 1.5. We
have now narrowed the root down to between 1.0 and 1.5.

Continue doing this until high and low are the same.

Actually there is a technical difficulty here in that it is just possible
that high and low may always be 1 bit off because of the way your
floating-point package works. So you could terminate when the difference
goes to less than some tiny value.
Nov 14 '05 #16

"P.J. Plauger" <pj*@dinkumware .com> wrote in message
Sun Sparcs are in pretty common use. They have 128-bit floating-
point format. And every compiler I know calls it long double.

So what do they use for 80 bits?
Nov 14 '05 #17
Keith Thompson wrote:
CBFalconer <cb********@yah oo.com> writes:
.... snip ...
No it isn't (just made up). AGMTA.


"AGMTA"?


All Great Minds Think Alike

--
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 #18
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
CBFalconer <cb********@yah oo.com> writes:
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.


"AGMTA"?


I've seen it used as: Acting General Manager's Travel Allowance.

Perhaps it means Astute Googling Manifests Technical Answers?

Sadly, all I could find was a reference to All Goa Milk Traders Association.
Jayant Katkar was elected President by the way... <g>

--
Peter
Nov 14 '05 #19

"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote in message
news:bv******** **@newsg3.svr.p ol.co.uk...

"P.J. Plauger" <pj*@dinkumware .com> wrote in message
Sun Sparcs are in pretty common use. They have 128-bit floating-
point format. And every compiler I know calls it long double.

So what do they use for 80 bits?

I don't think anyone has been motivated to tackle the support of 2 different
long double floating point types in a C compiler. Platforms which could
support that somewhat efficiently (e.g. Itanium) are rare enough that it
surely wouldn't be portable.
C allows long double to be anything from the same as double on up, with no
mandate for it for it to resemble one of the optional types defined by IEEE
standards.
Microsoft appears to be ruling out entirely the possibility of long double
differing from double in a large part of their sphere of influence.
Nov 14 '05 #20

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

Similar topics

4
3321
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
3758
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
23911
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
2271
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
3881
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
2418
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
3940
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
18787
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
6765
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
3593
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
10757
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...
1
10860
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
10420
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7975
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
5804
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
6002
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4620
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
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3239
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.