diff --git a/mnist-idx.cabal b/mnist-idx.cabal
--- a/mnist-idx.cabal
+++ b/mnist-idx.cabal
@@ -1,6 +1,6 @@
 name:                mnist-idx
 
-version:             0.1.3.0
+version:             0.1.3.1
 
 -- A short (one-line) description of the package.
 synopsis:            Read and write IDX data that is used in e.g. the MNIST database.
diff --git a/src/Data/IDX/Internal.hs b/src/Data/IDX/Internal.hs
--- a/src/Data/IDX/Internal.hs
+++ b/src/Data/IDX/Internal.hs
@@ -20,6 +20,11 @@
 import           Control.Monad (replicateM)
 import           Data.Binary
 import           Data.Int
+import           GHC.Float ( castFloatToWord32
+                           , castDoubleToWord64
+                           , castWord64ToDouble
+                           , castWord32ToFloat
+                           )
 
 import qualified Data.Vector.Unboxed as V
 import           Data.Vector.Unboxed ((!))
@@ -191,10 +196,10 @@
 getInt32 = get
 
 getFloat :: Get Float
-getFloat = get
+getFloat = castWord32ToFloat <$> get
 
 getDouble :: Get Double
-getDouble = get
+getDouble = castWord64ToDouble <$> get
 
 -- | Helper function for parsing integer data from the
 -- IDX content. Returns a full IDX result.
@@ -234,8 +239,8 @@
 
 -- | Put real values that are saved as Double
 putReal :: IDXContentType -> Double -> Put
-putReal IDXDouble n = put n
-putReal IDXFloat  n = put $! (realToFrac n :: Float )
+putReal IDXDouble n = put $ castDoubleToWord64 n
+putReal IDXFloat  n = put $! castFloatToWord32 (realToFrac n :: Float )
 
 -- | Split data by the first dimension of the C-Array. This would e.g. split a
 -- data-set of images into a list of data representing an individual image
