From 2158e772ec0d23c9f656d4501985d4d9cc4750ed Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 14 Sep 2012 08:43:29 -0700 Subject: [PATCH] math.order: speed up math comparisons using a math generic. --- core/math/order/order.factor | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/math/order/order.factor b/core/math/order/order.factor index 499cf06e9a..702c54376b 100644 --- a/core/math/order/order.factor +++ b/core/math/order/order.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel math ; +USING: kernel kernel.private math ; IN: math.order SYMBOL: +lt+ @@ -15,7 +15,22 @@ GENERIC: <=> ( obj1 obj2 -- <=> ) : >=< ( obj1 obj2 -- >=< ) <=> invert-comparison ; inline -M: real <=> 2dup < [ 2drop +lt+ ] [ number= +eq+ +gt+ ? ] if ; inline +) ( x y -- ? ) + 2dup < [ 2drop +lt+ ] [ number= +eq+ +gt+ ? ] if ; inline + +MATH: number<=> ( x y -- ? ) +M: fixnum number<=> { fixnum fixnum } declare (number<=>) ; inline +M: bignum number<=> { bignum bignum } declare (number<=>) ; inline +M: float number<=> { float float } declare (number<=>) ; inline +M: real number<=> (number<=>) ; inline + +PRIVATE> + +M: real <=> number<=> ; inline GENERIC: before? ( obj1 obj2 -- ? ) GENERIC: after? ( obj1 obj2 -- ? )