Floating Point Interval

Just chiming in here to say that you can use simd_mix instead of linearInterpolate (it's also not in the standard lib though)

1 Like

Hi Wolf,

Thank you for sharing this. A few comments:

There is a lot of prior work on real intervals, including work in
the computer graphics field, that you may find useful. A theory
of interval arithmetic was elaborated in the '50s and '60s by Ramon
E. Moore. Interval arithmetic has seen many applications in science
and engineering in the mean time. The article by Daniel L. Toth
in the 1985 proceedings of ACM SIGGRAPH, "On Ray Tracing Parametric
Surfaces," describes a notable use of interval arithmetic in computer
graphics.

I know from experience that Swift is a great language for programming
interval arithmetic. I also have programmed automatic differentiation
in Swift. I read recently about Swift's new, built-in automatic
differentation. Just as there are advantages to building
differentiation into the compiler instead of into a library,
building-in interval arithmetic may be advantageous.

I agree with the earlier commenter who said your interval, being
ordered, is more like a directed segment on the real line than what
I think of as an interval. You can call your intervals whatever
you like, of course! :-)

Dave

2 Likes

Thanks for pointing that out. I notice that the many variants of simd_mix are declared as C inline functions, and not part of any protocol:

static inline SIMD_CFUNC simd_float2 simd_mix(simd_float2 x, simd_float2 y, simd_float2 t) {
  return x + t*(y - x);
}

My new implementation is also inlinable, and does the same thing for all SIMD types, but with a single generic implementation, and can work in pure Swift:

extension SIMD where Scalar: FloatingPoint {
    @inlinable public func interpolate(to other: Self, at t: Self.Scalar) -> Self {
        t * (other - self) + self
    }
}