! Copyright (C) 2013 John Benediktsson ! See http://factorcode.org/license.txt for BSD license USING: combinators kernel layouts math math.bitwise math.floating-point math.functions ; IN: math.hashcodes GENERIC: number-hashcode ( x -- h ) M: integer number-hashcode 1 hash-fraction ; M: ratio number-hashcode >fraction hash-fraction ; M: float number-hashcode ( x -- h ) { { [ dup fp-nan? ] [ drop 0 ] } { [ dup fp-infinity? ] [ 0 > 314159 -314159 ? ] } [ double>ratio number-hashcode ] } cond ; M: complex number-hashcode ( x -- h ) >rect [ number-hashcode ] bi@ 1000003 * + cell-bits on-bits bitand dup -1 = [ drop -2 ] when ;