diff --git a/pdf.c b/pdf.c
index 6e9b60c1759982ea6e4d4d1e84a5c8d8f9f41dcc..3307ace2c5d7db19e8359f5152e4e8eea17c0eb5 100644
--- a/pdf.c
+++ b/pdf.c
@@ -1605,8 +1605,10 @@ act_tnumb(const HParseResult *p, void *u)
 
 	double value;
 
-	if (p->ast->token_type == TT_SINT)  value = (double)p->ast->sint;
-	else                                value =         p->ast->dbl;
+	if (p->ast->token_type == TT_SINT)
+	  value = (double)p->ast->sint;
+	else
+	  value = H_CAST_DOUBLE(p->ast);
 
 	return H_MAKE_DOUBLE(value);
 }
@@ -5026,20 +5028,28 @@ void parse_pagenode (
             double llx, lly, urx, ury; // typical but can be any diagonal
             HParsedToken * token;
             token = H_INDEX_TOKEN(item, 0);
-            if (token->token_type == TT_SINT)  llx = (double)token->sint;
-            else                               llx =         token->dbl;
+            if (token->token_type == TT_SINT)
+              llx = (double)token->sint;
+            else
+              llx = H_CAST_DOUBLE(token);
             token = H_INDEX_TOKEN(item, 1);
-            if (token->token_type == TT_SINT)  lly = (double)token->sint;
-            else                               lly =         token->dbl;
+            if (token->token_type == TT_SINT)
+              lly = (double)token->sint;
+            else
+              lly = H_CAST_DOUBLE(token);
             token = H_INDEX_TOKEN(item, 2);
-            if (token->token_type == TT_SINT)  urx = (double)token->sint;
-            else                               urx =         token->dbl;
+            if (token->token_type == TT_SINT)
+              urx = (double)token->sint;
+            else
+              urx = H_CAST_DOUBLE(token);
             token = H_INDEX_TOKEN(item, 3);
-            if (token->token_type == TT_SINT)  ury = (double)token->sint;
-            else                               ury =         token->dbl;
+            if (token->token_type == TT_SINT)
+              ury = (double)token->sint;
+            else
+              ury = H_CAST_DOUBLE(token);
 
             myNode->mediaBox.tx = fabs(llx - urx);
-            myNode->mediaBox.ty = fabs(lly - ury);;
+            myNode->mediaBox.ty = fabs(lly - ury);
         }
     }
 
@@ -5266,19 +5276,27 @@ parse_pagetree(
 	        double llx, lly, urx, ury; // typical but can be any diagonal
 	        HParsedToken * token;
 	        token = H_INDEX_TOKEN(item, 0);
-	        if (token->token_type == TT_SINT)  llx = (double)token->sint;
-	        else                               llx =         token->dbl;
+	        if (token->token_type == TT_SINT)
+	          llx = (double)token->sint;
+	        else
+	          llx = H_CAST_DOUBLE(token);
                 token = H_INDEX_TOKEN(item, 1);
-                if (token->token_type == TT_SINT)  lly = (double)token->sint;
-                else                               lly =         token->dbl;
+                if (token->token_type == TT_SINT)
+                  lly = (double)token->sint;
+                else
+                  lly = H_CAST_DOUBLE(token);
                 token = H_INDEX_TOKEN(item, 2);
-                if (token->token_type == TT_SINT)  urx = (double)token->sint;
-                else                               urx =         token->dbl;
+                if (token->token_type == TT_SINT)
+                  urx = (double)token->sint;
+                else
+                  urx = H_CAST_DOUBLE(token);
                 token = H_INDEX_TOKEN(item, 3);
-                if (token->token_type == TT_SINT)  ury = (double)token->sint;
-                else                               ury =         token->dbl;
+                if (token->token_type == TT_SINT)
+                  ury = (double)token->sint;
+                else
+                  ury = H_CAST_DOUBLE(token);
                 myNode->mediaBox.tx = fabs(llx - urx);
-                myNode->mediaBox.ty = fabs(lly - ury);;
+                myNode->mediaBox.ty = fabs(lly - ury);
 	    }
 	}