math.parser: simplify fix-float (from 16c93c7874)

db4
Jon Harper 2015-10-08 00:08:34 +02:00 committed by John Benediktsson
parent cac9b58f11
commit 7eaa24b3e0
1 changed files with 9 additions and 7 deletions

View File

@ -488,12 +488,13 @@ M: ratio >base
<PRIVATE <PRIVATE
: fix-float ( str exponent -- newstr ) : (fix-float) ( str-no-exponent -- newstr )
2dup first swap member? [ CHAR: . over member? [ ".0" append ] unless ; inline
[ [ split1 ] keep swap [ fix-float ] dip ] [ glue ] bi
] [ : fix-float ( str exponent-char -- newstr )
drop CHAR: . over member? [ ".0" append ] unless over index [
] if ; cut [ (fix-float) ] dip append
] [ (fix-float) ] if* ; inline
: mantissa-expt-normalize ( mantissa expt -- mantissa' expt' ) : mantissa-expt-normalize ( mantissa expt -- mantissa' expt' )
[ dup log2 52 swap - [ shift 52 2^ 1 - bitand ] [ 1022 + neg ] bi ] [ dup log2 52 swap - [ shift 52 2^ 1 - bitand ] [ 1022 + neg ] bi ]
@ -553,7 +554,8 @@ M: ratio >base
[ format-string ] 4dip [ format-string ] bi@ (format-float) [ format-string ] 4dip [ format-string ] bi@ (format-float)
dup [ 0 = ] find drop format-head dup [ 0 = ] find drop format-head
] [ ] [
"C" = [ [ "G" = ] [ "E" = ] bi or "E" "e" ? fix-float ] [ drop ] if "C" = [ [ "G" = ] [ "E" = ] bi or CHAR: E CHAR: e ? fix-float ]
[ drop ] if
] 2bi ; inline ] 2bi ; inline
: float>base ( n radix -- str ) : float>base ( n radix -- str )