From e640c9db4fce249c65e1319c95708d940705ea64 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 18 Mar 2009 19:01:29 +0000 Subject: [PATCH] 2009-03-18 20:07 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/minmax.c ! fixed min()/max() functions to always return the 1-st item when items are equal. It's Clipper behavior and can be important when two items with the same wight have different other attributes like formatted value size or number of decimal places. --- harbour/ChangeLog | 7 +++++++ harbour/source/rtl/minmax.c | 42 ++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 18a0b63125..11fa16fedd 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,13 @@ 2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-03-18 20:07 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/rtl/minmax.c + ! fixed min()/max() functions to always return the 1-st item when + items are equal. It's Clipper behavior and can be important when + two items with the same wight have different other attributes + like formatted value size or number of decimal places. + 2009-03-18 19:59 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/bin/hb-mkdyn.bat * harbour/config/linux/icc.cf diff --git a/harbour/source/rtl/minmax.c b/harbour/source/rtl/minmax.c index 494067b968..f95c631139 100644 --- a/harbour/source/rtl/minmax.c +++ b/harbour/source/rtl/minmax.c @@ -55,6 +55,7 @@ #include "hbapierr.h" /* returns the maximum of two date or numerics */ +/* NOTE: CA-Cl*pper returns 1-st item when they are equal [druzus] */ HB_FUNC( MAX ) { PHB_ITEM p1 = hb_param( 1, HB_IT_ANY ); @@ -67,7 +68,10 @@ HB_FUNC( MAX ) HB_LONG l1 = hb_itemGetNInt( p1 ); HB_LONG l2 = hb_itemGetNInt( p2 ); - hb_retnint( l1 >= l2 ? l1 : l2 ); + if( l1 >= l2 ) + hb_itemReturn( p1 ); + else + hb_itemReturn( p2 ); return; } else if( HB_IS_NUMERIC( p1 ) && HB_IS_NUMERIC( p2 ) ) @@ -75,16 +79,10 @@ HB_FUNC( MAX ) double d1 = hb_itemGetND( p1 ); double d2 = hb_itemGetND( p2 ); - int iDec1; - int iDec2; - - hb_itemGetNLen( p1, NULL, &iDec1 ); - hb_itemGetNLen( p2, NULL, &iDec2 ); - if( d1 >= d2 ) - hb_retndlen( d1, 0, iDec1 ); + hb_itemReturn( p1 ); else - hb_retndlen( d2, 0, iDec2 ); + hb_itemReturn( p2 ); return; } else if( HB_IS_LOGICAL( p1 ) && HB_IS_LOGICAL( p2 ) ) @@ -97,9 +95,10 @@ HB_FUNC( MAX ) } else if( HB_IS_DATE( p1 ) && HB_IS_DATE( p2 ) ) { - char szDate[ 9 ]; + LONG l1 = hb_itemGetDL( p1 ); + LONG l2 = hb_itemGetDL( p2 ); - hb_retds( hb_itemGetDL( p1 ) >= hb_itemGetDL( p2 ) ? hb_pardsbuff( szDate, 1 ) : hb_pardsbuff( szDate, 2 ) ); + hb_retdl( l1 >= l2 ? l1 : l2 ); return; } } @@ -107,6 +106,7 @@ HB_FUNC( MAX ) } /* returns the minimum of two date or numerics */ +/* NOTE: CA-Cl*pper returns 1-st item when they are equal [druzus] */ HB_FUNC( MIN ) { PHB_ITEM p1 = hb_param( 1, HB_IT_ANY ); @@ -119,7 +119,10 @@ HB_FUNC( MIN ) HB_LONG l1 = hb_itemGetNInt( p1 ); HB_LONG l2 = hb_itemGetNInt( p2 ); - hb_retnint( l1 <= l2 ? l1 : l2 ); + if( l1 <= l2 ) + hb_itemReturn( p1 ); + else + hb_itemReturn( p2 ); return; } else if( HB_IS_NUMERIC( p1 ) && HB_IS_NUMERIC( p2 ) ) @@ -127,16 +130,10 @@ HB_FUNC( MIN ) double d1 = hb_itemGetND( p1 ); double d2 = hb_itemGetND( p2 ); - int iDec1; - int iDec2; - - hb_itemGetNLen( p1, NULL, &iDec1 ); - hb_itemGetNLen( p2, NULL, &iDec2 ); - if( d1 <= d2 ) - hb_retndlen( d1, 0, iDec1 ); + hb_itemReturn( p1 ); else - hb_retndlen( d2, 0, iDec2 ); + hb_itemReturn( p2 ); return; } else if( HB_IS_LOGICAL( p1 ) && HB_IS_LOGICAL( p2 ) ) @@ -149,9 +146,10 @@ HB_FUNC( MIN ) } else if( HB_IS_DATE( p1 ) && HB_IS_DATE( p2 ) ) { - char szDate[ 9 ]; + LONG l1 = hb_itemGetDL( p1 ); + LONG l2 = hb_itemGetDL( p2 ); - hb_retds( hb_itemGetDL( p1 ) <= hb_itemGetDL( p2 ) ? hb_pardsbuff( szDate, 1 ) : hb_pardsbuff( szDate, 2 ) ); + hb_retdl( l1 <= l2 ? l1 : l2 ); return; } }