FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour harbour 3.0 ceiling(101.2/2.53)==41 bug?
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
harbour 3.0 ceiling(101.2/2.53)==41 bug?
Posted: Wed Dec 12, 2012 09:21 AM

Hi, call Harbour 3.0 function
?ceiling(101.2/2.53)
// 41
// Should be 40.
Regards!
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: harbour 3.0 ceiling(101.2/2.53)==41 bug?
Posted: Wed Dec 12, 2012 09:35 AM
I get the same result using this C sample:

Code (fw): Select all Collapse
#include <stdio.h>
#include <math.h>


int main()
{
    printf( "%lf\n", ceil( 101.2 / 2.53 ) );
    return 0;
}


It's a well known problem with floating-point numbers. The result of the division is probably a little more than 40 (ie. 40.000000000001) so ceil() gives 41. You have to working around the problem using some sort of rounding.

EMG
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
Re: harbour 3.0 ceiling(101.2/2.53)==41 bug?
Posted: Wed Dec 12, 2012 09:42 AM

EMG,
2.53X40==101.20
MySQL select ceiling(101.2/2.53)
// 40
Regards!
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: harbour 3.0 ceiling(101.2/2.53)==41 bug?
Posted: Wed Dec 12, 2012 11:30 AM

Please read something about floating-point numbers. I repeat: it's a well known problem and no, it's not specific of a particular programming language.

EMG

Continue the discussion