[<<][math][>>][..]
Tue Jan 28 10:17:19 CET 2014

Where > and >= are the same.

Everyone tells you, you can't compare floats for equality.

This is an interesting problem in fact.  Equality doesn't really make
sense when your only functions are smooth functions, which is often
the case.  Non-smooth functions are often implementation artifacts,
such as mapping (wrapping) the real line onto a circle.  True
"thresholding" often meeds smooth squashing functions without
discontinuities.

( TODO: Find out how this relates to smooth infinitesimal analysis[1]. )

[1] http://en.wikipedia.org/wiki/Smooth_infinitesimal_analysis


From rai/prim.h:

/* Note that this is based on float to int truncation, so is not the
   same as the floor() function from math.h

   For negative integers, the map is n -> n - 1.

   In practical use in numerical algorithms this difference is OK.
   Think of it this way: in the presence of noise, there is no real
   difference between > and >=.
*/

#define _ float
#define i_ int

INLINE i_ p_ifloor(_ a) {
    i_ i_truncate = (i_)a;
    i_ i_negative = a < 0;
    i_ i_floor = i_truncate - i_negative;
    return i_floor;
}

INLINE _ p_floor(_ a) {
    _ f_floor = (_)p_ifloor(a);
    return f_floor;
}

from rai/stream-lib.rkt:

;; Map phase value to the [0,1] representation interval.
;;
;; Note that floor(n) for n integer and n < 0 maps n -> n - 1.
;; This means that wrap01 for n integer and n < 0 maps n -> 1.
;;
;; This is OK for "phase" values, i.e. those that are at some point
;; inserted into cos(2*pi*phase) or sin(2*pi*phase), since all
;; integers map to a single point.

(define (wrap01 x) (- x (floor x))) 




[Reply][About]
[<<][math][>>][..]