Safe casting functions

https://wiki.php.net/rfc/safe_cast
With this patch applied:

```
diff --git a/ext/standard/type.c b/ext/standard/type.c
index 3c1d4a7..12e5320 100644
--- a/ext/standard/type.c
+++ b/ext/standard/type.c
@@ -546,25 +546,7 @@ PHP_FUNCTION(to_string)
                        RETURN_STR(zend_long_to_str(Z_LVAL_P(var)));
 
                case IS_DOUBLE:
-                       /* This code, despite being used in many other places, segfaults
-                        * Since I can't figure out why, it's commented out for now
-                        * This is a shame, as an extra malloc is always bad
-                        * TODO: Stop this segfaulting so we can use it instead
-                        */ 
-                       /*RETVAL_STR(zend_strpprintf("%.*G", (int) EG(precision), Z_DVAL_P(var)));*/
-
-                       {
-                               char *str;
-                               zend_string *zstr;
-                               int len;
-
-                               str = emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1);
-                               len = zend_sprintf(str, "%.*G", (int) EG(precision), Z_DVAL_P(var));
-                               zstr = zend_string_init(str, len, 0);
-                               RETVAL_STR(zstr);
-                               efree(str);
-                       }
-                       return;
+                       RETURN_STR(strpprintf(0, "%.*G", (int) EG(precision), Z_DVAL_P(var)));
 
                case IS_OBJECT:
                        {
```

I pass to_string test.