double f1 = 0.00000001; double f2 =  7.00000001; double f3 = -7.00000000; double sum = f2 + f3; bool shouldBeTrue = sum == f1;   shouldBeTrue is false using VS C++ 2015/2017  float f1 = 0.00001; float f2 = 7.00001; float f3 = -7.00000; float sum = f2 + f3; bool shouldBeTrue = sum == f1;   shouldBeTrue is false using VS C++ 2015/2017  how to implement this in c++ so I can store the values written in the code and not the approximations? any new types or library available?  (e.g. like decimal type in c#)
27
Consider the following code:   0.1 + 0.2 == 0.3  -&gt;  false   0.1 + 0.2         -&gt;  0.30000000000000004   Why do these inaccuracies happen?
73742
What is the best way to handle large numeric inputs in C++ (for example 10^100)?   For algorithms I usually switch over to ruby and I sometimes use strings.  Any other good methods?
40138
What's the proper way to convert from a scientific notation string such as "1.234567E-06" to a floating point variable using C#?
58941
I want to use a Track-Bar to change a Form's opacity. This is my code: decimal trans = trackBar1.Value / 5000; this.Opacity = trans;  When I build the application, it gives the following error:  Cannot implicitly convert type decimal to double   I have tried using trans and double, but then the Control doesn't work. This code worked fine in a past VB.NET project.
87887
I need a simple floating point rounding function, thus:   double round(double);  round(0.1) = 0 round(-0.1) = 0 round(-0.9) = -1   I can find ceil() and floor() in the math.h - but not round().  Is it present in the standard C++ library under another name, or is it missing??
29904
If I have a double (234.004223), etc., I would like to round this to x significant digits in C#.  So far I can only find ways to round to x decimal places, but this simply removes the precision if there are any 0s in the number.  For example, 0.086 to one decimal place becomes 0.1, but I would like it to stay at 0.08.
66958
I want to do:  int a = 255;  cout &lt;&lt; a;   and have it show FF in the output, how would I do this?
29737
I'm writing an application which reads large arrays of floats and performs some simple operations with them. I'm using floats, because I thought it'd be faster than doubles, but after doing some research I've found that there's some confusion about this topic. Can anyone elaborate on this?
9601
I want to take a floating point number in C++, like 2.25125, and a int array filled with the binary value that is used to store the float in memory (IEEE 754).  So I could take a number, and end up with a int num[16] array with the binary value of the float: num[0] would be 1 num[1] would be 1 num[2] would be 0 num[3] would be 1 and so on...  Putting an int into an array isn't difficult, just the process of getting the binary value of a float is where I'm stuck. Can you just read the binary in the memory that the float variable? If not, how could I go about doing this in C++?  EDIT: The reason for doing the comparison this way is that I am wanting to learn to do bitwise operations in C++.
80880
My code:  a = '2.3'   I wanted to display a as a floating point value.  Since a is a string, I tried:  float(a)   The result I got was :  2.2999999999999998   I want a solution for this problem. Please, kindly help me.  I was following .
112920
How can I round a decimal number (floating point) to the nearest integer?   e.g.  1.2 = 1 1.7 = 2
23208
I have been asked to test a library provided by a 3rd party. The library is known to be accurate to n significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:  def nearlyequal( a, b, sigfig=5 ):   The purpose of this function is to determine if two floating-point numbers (a and b) are approximately equal. The function will return True if a==b (exact match) or if a and b have the same value when rounded to sigfig significant-figures when written in decimal.   Can anybody suggest a good implementation? I've written a mini unit-test. Unless you can see a bug in my tests then a good implementation should pass the following:  assert nearlyequal(1, 1, 5)  assert nearlyequal(1.0, 1.0, 5)  assert nearlyequal(1.0, 1.0, 5)  assert nearlyequal(-1e-9, 1e-9, 5)  assert nearlyequal(1e9, 1e9 + 1 , 5)  assert not nearlyequal( 1e4, 1e4 + 1, 5)  assert nearlyequal( 0.0, 1e-15, 5 )  assert not nearlyequal( 0.0, 1e-4, 6 )    Additional notes:   Values a and b might be of type int, float or numpy.float64. Values a and b will always be of the same type. It's vital that conversion does not introduce additional error into the function. Lets keep this numerical, so functions that convert to strings or use non-mathematical tricks are not ideal. This program will be audited by somebody who is a mathematician who will want to be able to prove that the function does what it is supposed to do. Speed... I've got to compare a lot of numbers so the faster the better. I've got numpy, scipy and the standard-library. Anything else will be hard for me to get, especially for such a small part of the project.
27648
double r = 11.631; double theta = 21.4;   In the debugger, these are shown as 11.631000000000000 and 21.399999618530273.  How can I avoid this?
7810
For any $\epsilon$, if $\epsilon&gt;0$ and $|x|&lt;\epsilon$, then $x=0$.  I understand that supposing  $\epsilon=\frac{x}{2}$ will lead to a contradiction, but let’s take a correct case: Let $\epsilon=3$, then $x$ would have a whole set of values. Can you explain what is going on?
63628
Here's an example:  Double d = (1/3); System.out.println(d);   This returns 0, not 0.33333... as it should.  Does anyone know?
6847
How do I convert between big-endian and little-endian values in C++? For clarity, I have to translate binary data (double-precision floating point values and 32-bit and 64-bit integers) from one CPU architecture to another.  This doesn't involve networking, so ntoh() and similar functions won't work here.  Note: The answer I accepted applies directly to compilers I'm targeting (which is why I chose it).  However, there are other very good, more portable answers here.
45124
My TI-83 calculator doesnt allow me to do this, but using Windows calculator, I can compute the factorial of say 5.8. What does this mean and how does it work?