From 866b40271d774a0d4e5b9afc98acf39fdf834395 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 14 Jul 2015 20:03:33 -0700 Subject: [PATCH] math.parser: fix "most-negative-fixnum number>string string>number fixnum?". --- core/math/parser/parser-tests.factor | 6 +++++- core/math/parser/parser.factor | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/math/parser/parser-tests.factor b/core/math/parser/parser-tests.factor index dbc24f6f66..909c630265 100644 --- a/core/math/parser/parser-tests.factor +++ b/core/math/parser/parser-tests.factor @@ -1,4 +1,5 @@ -USING: kernel literals math math.parser sequences tools.test ; +USING: kernel layouts literals math math.parser sequences +tools.test ; IN: math.parser.tests { f } @@ -359,3 +360,6 @@ unit-test { f } [ "0b0" bin> ] unit-test { f } [ "0o0" bin> ] unit-test { f } [ "0x0" bin> ] unit-test + +{ t } [ most-positive-fixnum number>string string>number fixnum? ] unit-test +{ t } [ most-negative-fixnum number>string string>number fixnum? ] unit-test diff --git a/core/math/parser/parser.factor b/core/math/parser/parser.factor index c10ac80cd5..8502e6ae5f 100644 --- a/core/math/parser/parser.factor +++ b/core/math/parser/parser.factor @@ -98,7 +98,12 @@ TUPLE: float-parse } cond ; : ?neg ( n/f -- -n/f ) - [ neg ] [ f ] if* ; inline + [ + dup bignum? [ + dup first-bignum bignum= + [ drop most-negative-fixnum ] [ neg ] if + ] [ neg ] if + ] [ f ] if* ; inline : ?add-ratio ( m n/f -- m+n/f ) dup ratio? [ + ] [ 2drop f ] if ; inline