harbour 3.0 ceiling(101.2/2.53)==41 bug?

harbour 3.0 ceiling(101.2/2.53)==41 bug?

Postby ShumingWang » Wed Dec 12, 2012 9: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
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Re: harbour 3.0 ceiling(101.2/2.53)==41 bug?

Postby Enrico Maria Giordano » Wed Dec 12, 2012 9:35 am

I get the same result using this C sample:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: harbour 3.0 ceiling(101.2/2.53)==41 bug?

Postby ShumingWang » Wed Dec 12, 2012 9: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
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Re: harbour 3.0 ceiling(101.2/2.53)==41 bug?

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 117 guests