[Haskell-cafe] Re: New OpenGL package: efficient way to convert datatypes?

Nick Bowler nbowler at elliptictech.com
Fri Mar 5 10:33:26 EST 2010


On 14:30 Fri 05 Mar     , Achim Schneider wrote:
> Nick Bowler <nbowler at elliptictech.com> wrote:
> > I meant to say that "fromRational . toRational" is not appropriate for
> > converting values from one floating point type to another floating
> > point type.
> 
> It gets even worse: My GPU doesn't know about doubles and its floats
> aren't IEEE, at all (not that Haskell Doubles are guaranteed to be IEEE
> iirc)

AFAIK, GLDouble is a newtype wrapper around CDouble, though, and doesn't
correspond to a GPU-internal type.  Even if it did, if we are converting
to a type that doesn't support infinities, then is is reasonable for the
conversion to not support them, either.  I'd want to see a call to error
in this case, but perhaps allowing "unsafe" optimisations (see below).

> I think the situation calls for a split interface: One to satisfy the
> numericists / scientific IEEE users, and one to satisfy performance.

I think this is a job for the compiler rather than the interface.  For
example, GCC has -ffinite-math-only, -fno-signed-zeros, etc., which
allow the compiler to make assumptions about the program that would not
normally be valid.

Nevertheless, for the issue at hand (Double<=>CDouble<=>GLDouble), there
is a conversion interface that should satisfy everyone (both fast and
correct): the one that compiles to nothing at all.

-- 
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)


More information about the Haskell-Cafe mailing list