I would like to know that why float datayppe never stores exact value that is assigned to them?
for eg-> A piece of code
main()
{
float a=.07;
if (a<0.7)
printf("mismatch");
else
printf("C is precise");
}
Output: mismatch
7 2283
Question moved to C Forum.
I would like to know that why float datayppe never stores exact value that is assigned to them?
for eg-> A piece of code
main()
{
float a=.07;
if (a<0.7)
printf("mismatch");
else
printf("C is precise");
}
Output: mismatch
you have assigned 0.07 to a, and comparing with 0.7... obviously there is a mismatch
0.07<0.7, it's a normal logic. So if(a<0.7) fulfills the condition and output will be mismatch!!
Regards
I would like to know that why float datayppe never stores exact value that is assigned to them?
for eg-> A piece of code
main()
{
float a=.07;
if (a<0.7)
printf("mismatch");
else
printf("C is precise");
}
Output: mismatch
If you want to make your code "interactive" with the user, google for "c scanf"
You can change your code to: - main()
-
{
-
float a;
-
-
printf("input a float value\n");
-
scanf("%f", &a);
-
-
if (a<0.7)
-
printf("mismatch");
-
else
-
printf("C is precise");
-
}
you have assigned 0.07 to a, and comparing with 0.7... obviously there is a mismatch
actually i typed it wrongly, the value assigned to a is 0.7, then there is a mismatch. Kindly let me know.
actually i typed it wrongly, the value assigned to a is 0.7, then there is a mismatch. Kindly let me know.
You cannot compare floats with < operator,because of float point accuracy.Epsilon is your friend.See this ..
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve |
last post by:
Hi,
I've developed a testing application that stores formatted results in a
database. Recently it was requested that I add the ability to generate
graphs from the raw, un formatted test results...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm reading a number of double values from a file. It's a 2D-array:
1 2 3 4 5 6 7
-------------
1 3.2
2 0 2.1
3 9.3
4
|
by: veremue |
last post by:
I want to store a float/double as String. I have an input file with a column with float values i.e. have the form 1.4E15. I want to store these values as Strings. Here is my code which is resulting...
|
by: Josip |
last post by:
I'm trying to limit a value stored by object (either int or float):
class Limited(object):
def __init__(self, value, min, max):
self.min, self.max = min, max
self.n = value
def...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |