factor/extra/float-vectors/float-vectors.factor

52 lines
1.3 KiB
Factor
Raw Normal View History

2008-01-28 19:15:21 -05:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays kernel kernel.private math sequences
sequences.private growable float-arrays prettyprint.backend
2008-04-20 03:30:52 -04:00
parser accessors ;
2008-01-28 19:15:21 -05:00
IN: float-vectors
2008-04-20 01:18:27 -04:00
TUPLE: float-vector underlying fill ;
M: float-vector underlying underlying>> { float-array } declare ;
M: float-vector set-underlying (>>underlying) ;
M: float-vector length fill>> { array-capacity } declare ;
M: float-vector set-fill (>>fill) ;
2008-01-28 19:15:21 -05:00
<PRIVATE
2008-01-30 02:10:58 -05:00
: float-array>vector ( float-array length -- float-vector )
float-vector boa ; inline
2008-01-28 19:15:21 -05:00
PRIVATE>
: <float-vector> ( n -- float-vector )
2008-01-29 16:04:26 -05:00
0.0 <float-array> 0 float-array>vector ; inline
2008-01-28 19:15:21 -05:00
2008-04-20 01:18:27 -04:00
: >float-vector ( seq -- float-vector )
T{ float-vector f F{ } 0 } clone-like ;
2008-01-28 19:15:21 -05:00
M: float-vector like
drop dup float-vector? [
dup float-array?
[ dup length float-array>vector ] [ >float-vector ] if
] unless ;
2008-04-13 13:54:58 -04:00
M: float-vector new-sequence
2008-01-30 02:10:58 -05:00
drop [ 0.0 <float-array> ] keep >fixnum float-array>vector ;
2008-01-28 19:15:21 -05:00
M: float-vector equal?
over float-vector? [ sequence= ] [ 2drop f ] if ;
M: float-array new-resizable drop <float-vector> ;
2008-01-28 19:15:21 -05:00
INSTANCE: float-vector growable
: FV{ \ } [ >float-vector ] parse-literal ; parsing
2008-04-20 01:18:27 -04:00
M: float-vector >pprint-sequence ;
M: float-vector pprint-delims drop \ FV{ \ } ;