Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert double to GLfloat in Haskell

I want to convert a Double to a GLfloat. I want to use it for comparations.

xM <- newIORef 0.0
zM <- newIORef 0.0
mobs <- newIORef []
mapM_ (\x -> colision x xM) mobs

mobs is fulled with a method.

colision mob xC = do
  xcama <- get xC
  --zcama <- get zC
  let menor = mob!!0
  let mayor = mob!!7
  --if xm>= xmin && xm <= xmax && zm >= zmin && zm <= zmax  then renderText (1, (-1.4)) $ "Dead"
  --else renderText (1, (-1.4)) $ "Warning..."
  renderText (1, (-1.4)) $ "Warning..."

When I try to compile it show me this error:

"Couldn't match type 'Foreign.C.Types.CDouble' with 'Foreign.C.Types.CFloat' Expected type :GLfloat

Actual type: GLdouble

-----Solution:------

I use this code:

import GHC.Float
  d2f = realToFrac :: GLdouble -> GLfloat
like image 498
Luis Adan Gonzalez Ramirez Avatar asked Oct 15 '25 16:10

Luis Adan Gonzalez Ramirez


1 Answers

The general function to use to convert between different floating point types (and some others, such as Rational) is realToFrac.

like image 102
Ørjan Johansen Avatar answered Oct 18 '25 07:10

Ørjan Johansen