Tags "floating-point" Result

Floating point division vs floating point multiplication

Is there any (non-microoptimization) performance gain by coding float f1 = 200f / 2 in comparision to float f2 = 200f * 0.5 A professor of mine told me a few years ago that floating point divisions were slower than floating point multiplications without elaborating the why. Does this statement hold for modern PC architecture? Update1 In re

it1352 2 2019-05-10

Floating point serialization, lexicographical comparison == floating point comparison

I'm looking for a way to serialize floating points so that in their serialized form a lexicographical comparison is the same as a floating point comparison. I think it is possible by storing it in the form: | signed bit (1 for positive) | exponent | significand | The exponent and the significand would be serialized as big-endian and the compleme

it1352 0 2019-05-14

floating point issue

I have a floating value as 0.1 entering from UI. But, while converting that string to float i am getting as 0.10...01. The problem is the appending of non zero digit. How do i tackle with this problem. Thanks, iSight Solution The best site I've ever seen that explains why some numbers can't be represented exactly is Harald Schmidt's IEEE754 C

it1352 0 2019-05-10

Floating Point Error

I have a strange error in my C Code: float cosTheta = someFunction(); cout << cosTheta << endl; // prints 1 on the console if (cosTheta == 1) { // doesn't enter this condition cout << "it is 1" << endl; } float sinTheta = sqrt(1 - pow(cosTheta, 2)); return (someVariable * sinTheta); The problem is: cosTheta i

it1352 0 2019-05-17

Floating point equivalence?

I want to be able to compare two doubles disregarding a possible precision loss. Is there a method already that handles this case? If not, is there a threshold/guideline to know how much is an adequate equivalence between two doubles? Solution The threshold is completely dependent to the problem itself. For some problems, you might consider 1.00

it1352 0 2019-05-06

floating point problems

Hello, I''m having trouble with floating point problems. I''m trying to write a function that calculates the distance between two cartesian points (integer coordinates). I have the function working, but it fails on one test case. Here is my function: double distance(int x1, int y1, int x2, int y2) { double deltax = (double)x1 - x2; double delta

it1352 2 2019-06-25

Floating point accuracy

I am writing a method which calculates the equation of a 2D Line in the form a*x b*y=1 //Given two points, find the equation of the line by solving two linear equations and then test the result. (For simplicity, assume that delta !=0 here) private boolean solveAndRetry(float x1,float y1, float x2,float y2) { float delta = x1 * y2 - x2 * y

it1352 0 2019-05-17

Floating point again

Yesterday I asked a floating point question, and I have another one. I am doing some computations where I use the results of the math.h (C language) sine, cosine and tangent functions. One of the developers muttered that you have to be careful of the return values of these functions and I should not make assumptions on the return values of the gcc

it1352 2 2019-05-10

floating point glitch

Is this only on solaris ? Python 2.3.3 (#1, Mar 19 2004, 16:18:33) [GCC 2.95.2 19991024 (release)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. a=[66.6, 333, 333, 1, 1234.5] print a.count(333), a.count(66.6), a.count(''x'') 2 1 0 a.append(333) print a [66.599999999999994,

it1352 3 2019-06-25

floating point precision

I have a program written in C# and some parts are writing in native C/C . I use doubles to calculate some values and sometimes the result is wrong because of too small precision. After some investigation i figured out that someone is setting the floating-point precision to 24-bits. My code works fine, when i reset the precision to at least 53-bits

it1352 0 2019-05-15