473,486 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

setting floating point precision problem

35 New Member
hi,

i need to set precision for floating point operations in the c++ program.
i have a number of files.Please tell me how to do it ,so that i don't have to make the change in all the files in the program.
Nov 15 '08 #1
2 4966
Banfa
9,065 Recognized Expert Moderator Expert
You can't set the precision of floating point calculations in C++.

You can use one of the basic types float, double and long double. These 3 types each have fix precision (7 digits for a float and 15 for a double), on many platforms double and long double have the same precision but for some it is bigger (18 for example on by Ubuntu using GCC).

You set the precision by choosing which basic type to use, the normal choice would be double. You would only choose float if lack on memory on your platform was an issue (a float takes 4 bytes of ram and a double 8). If you required extra precision and you platform supported it you might use long double.
Nov 15 '08 #2
eternalLearner
35 New Member
You can't set the precision of floating point calculations in C++.

You can use one of the basic types float, double and long double. These 3 types each have fix precision (7 digits for a float and 15 for a double), on many platforms double and long double have the same precision but for some it is bigger (18 for example on by Ubuntu using GCC).

You set the precision by choosing which basic type to use, the normal choice would be double. You would only choose float if lack on memory on your platform was an issue (a float takes 4 bytes of ram and a double 8). If you required extra precision and you platform supported it you might use long double.

Thanks a lot for the reply.
:)
Nov 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3284
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...
31
3613
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms....
5
3723
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...
687
22792
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...
21
12650
by: syntax | last post by:
hi, i need to get high presion float numbers. say, i need pi = 22/7.0 = 3.142857....(upto 80 digits) is it possible ? does gcc/g++ compiler can give such type of high precision?? plz...
24
2203
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...
5
2393
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...
1
2744
by: Shhnwz.a | last post by:
Hi, I have a problem regarding handling floating point error, specially Denormalisation error. I want to know is there any trick or technique to find bit length of the resultant before using and...
137
6563
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...
39
3515
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...
0
7094
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
7123
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,...
1
6839
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...
0
7305
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...
0
5427
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,...
1
4863
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...
0
3066
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...
0
1378
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 ...
0
259
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...

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.