]> granicus.if.org Git - postgresql/commitdiff
Replace ad-hoc atof() code with call to float4in, per Andrew Dunstan.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Oct 2004 21:47:07 +0000 (21:47 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Oct 2004 21:47:07 +0000 (21:47 +0000)
contrib/seg/expected/seg.out
contrib/seg/segparse.y

index cfa8171e6813b39bf001d80bb3bad311de9de3d7..49f4f7dee5d33523119df1afbe616f36a63d523e 100644 (file)
@@ -418,8 +418,7 @@ SELECT '1 e7'::seg AS seg;
 ERROR:  bad seg representation
 DETAIL:  syntax error at or near "e"
 SELECT '1e700'::seg AS seg;
-ERROR:  syntax error
-DETAIL:  numeric value 1e700 unrepresentable
+ERROR:  "1e700" is out of range for type real
 --
 -- testing the  operators
 --
index d0c2f188bc43ea33b90863f405834e70cf1e72ad..8a3b0b0160c378710744e0e0d9ca4aad46ddf947 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <math.h>
 
+#include "fmgr.h"
+#include "utils/builtins.h"
 #include "segdata.h"
 
 #undef yylex                  /* failure to redefine yylex will result in calling the */
@@ -129,22 +131,13 @@ deviation:
 %%
 
 
-float seg_atof ( char *value ) {
-  float result;
-  char *buf = (char *) palloc(256);
+float
+seg_atof(char *value)
+{
+       Datum datum;
 
-  errno = 0;
-  sscanf(value, "%f", &result);
-
-  if ( errno ) {
-    snprintf(buf, 256, "numeric value %s unrepresentable", value);
-    ereport(ERROR,
-                   (errcode(ERRCODE_SYNTAX_ERROR),
-                    errmsg("syntax error"),
-                    errdetail("%s", buf)));
-  }
-
-  return result;
+       datum = DirectFunctionCall1(float4in, CStringGetDatum(value));
+       return DatumGetFloat4(datum);
 }