From 938cb3ef5883b4a863d755409943eeda99f0df52 Mon Sep 17 00:00:00 2001 From: Patrick Abi Salloum Date: Mon, 30 Aug 2010 18:55:41 +0300 Subject: [PATCH] is-on-the-wrong-side only returns true when the rhs is on the wrong side of ALL the lhs --- src/core/operators.pm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/core/operators.pm b/src/core/operators.pm index 25b6c7a833a..3f273cb4598 100644 --- a/src/core/operators.pm +++ b/src/core/operators.pm @@ -386,14 +386,29 @@ our sub _HELPER_generate-series(@lhs, $rhs , :$exclude-limit) { } my sub is-on-the-wrong-side($type , $get-value-to-compare, $limit , @lhs ) { - my $first = @lhs[*-3] // @lhs[0]; return if $limit ~~ Code; - - if $type eq 'arithmetic' | 'geometric-switching-sign' | 'geometric-same-sign' { - ($get-value-to-compare(@lhs[*-2]) >= $get-value-to-compare(@lhs[*-1]) && $get-value-to-compare($limit) > $get-value-to-compare($first) ) + return unless $type eq 'arithmetic' | 'geometric-switching-sign' | 'geometric-same-sign'; + + my $first = $get-value-to-compare( @lhs[*-3] // @lhs[0] ); + my $second = $get-value-to-compare( @lhs[*-2] ); + my $third = $get-value-to-compare( @lhs[*-1] ); + my $limit-to-use = $get-value-to-compare( $limit ); + return unless ($second >= $third && $limit-to-use > $first ) + || + ($second <= $third && $limit-to-use < $first ); + + sub between($a , $b) { + my ( $first , $second ) = ( $get-value-to-compare($a) , $get-value-to-compare($b) ); + ($first >= $limit-to-use >= $second ) || - ($get-value-to-compare(@lhs[*-2]) <= $get-value-to-compare(@lhs[*-1]) && $get-value-to-compare($limit) < $get-value-to-compare($first) ); + ($first <= $limit-to-use <= $second ) + } + + my $i = @lhs.elems; + while ($i-- >1) { + return if between(@lhs[$i-1] , @lhs[$i]); #If the limit is between any two items it cannot be on the wrong side } + return True; } my sub infinite-series (@lhs, $next ) {