What is Floting point error?

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

What is Floting point error?

Post by ranacse05 »

plz check this code

************code removed***********

What is it? And how can i overcome this problem?
Last edited by ranacse05 on Tue Apr 24, 2007 7:07 pm, edited 1 time in total.
I like to solve problems.

stubbscroll
Experienced poster
Posts: 151
Joined: Tue Nov 16, 2004 7:23 pm
Location: Norway
Contact:

Post by stubbscroll »

If I spotted correctly, you are dividing by zero. You set d5=fabs(x1-x3), which is 0, and two lines later you divide by 2.0*d5.

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Post by ranacse05 »

thanks for your help,but if it is 0 then what should i do?should i use 0.0?
I like to solve problems.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Suppose x=0. So, for floating points you can assume that x is so close to zero. Now let eps = .00000001.

Code: Select all

if(x==0)
    do something...
    // replace it with
if( fabs(x) <eps ) // fabs(x) returns absolute value of x
    do something...
Ami ekhono shopno dekhi...
HomePage

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Replay

Post by ranacse05 »

Thanks jan bhai again,os this is the floting point error,
I like to solve problems.

techyboy
New poster
Posts: 1
Joined: Wed Nov 18, 2015 2:10 pm

Re: What is Floting point error?

Post by techyboy »

Can you please paste the source code or example code? if your problem is not solved yet.

Post Reply

Return to “C”