--
-- FLOAT4
--
CREATE TABLE FLOAT4_TBL (f1  float4);
INSERT INTO FLOAT4_TBL(f1) VALUES ('    0.0');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1004.30   ');
INSERT INTO FLOAT4_TBL(f1) VALUES ('     -34.84    ');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');
INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e-20');
-- test for over and under flow 
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e40');
ERROR:  type "real" value out of range: overflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e40');
ERROR:  type "real" value out of range: overflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('10e-40');
ERROR:  type "real" value out of range: underflow
INSERT INTO FLOAT4_TBL(f1) VALUES ('-10e-40');
ERROR:  type "real" value out of range: underflow
-- bad input
INSERT INTO FLOAT4_TBL(f1) VALUES ('       ');
ERROR:  invalid input syntax for type real: "       "
INSERT INTO FLOAT4_TBL(f1) VALUES ('xyz');
ERROR:  invalid input syntax for type real: "xyz"
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.0.0');
ERROR:  invalid input syntax for type real: "5.0.0"
INSERT INTO FLOAT4_TBL(f1) VALUES ('5 . 0');
ERROR:  invalid input syntax for type real: "5 . 0"
INSERT INTO FLOAT4_TBL(f1) VALUES ('5.   0');
ERROR:  invalid input syntax for type real: "5.   0"
INSERT INTO FLOAT4_TBL(f1) VALUES ('     - 3.0');
ERROR:  invalid input syntax for type real: "     - 3.0"
INSERT INTO FLOAT4_TBL(f1) VALUES ('123            5');
ERROR:  invalid input syntax for type real: "123            5"
-- special inputs
SELECT 'NaN'::float4;
 float4 
--------
    NaN
(1 row)

SELECT 'nan'::float4;
 float4 
--------
    NaN
(1 row)

SELECT '   NAN  '::float4;
 float4 
--------
    NaN
(1 row)

SELECT 'infinity'::float4;
  float4  
----------
 Infinity
(1 row)

SELECT '          -INFINiTY   '::float4;
  float4   
-----------
 -Infinity
(1 row)

-- bad special inputs
SELECT 'N A N'::float4;
ERROR:  invalid input syntax for type real: "N A N"
SELECT 'NaN x'::float4;
ERROR:  invalid input syntax for type real: "NaN x"
SELECT ' INFINITY    x'::float4;
ERROR:  invalid input syntax for type real: " INFINITY    x"
SELECT 'Infinity'::float4 + 100.0;
ERROR:  type "double precision" value out of range: overflow
SELECT 'Infinity'::float4 / 'Infinity'::float4;
 ?column? 
----------
      NaN
(1 row)

SELECT 'nan'::float4 / 'nan'::float4;
 ?column? 
----------
      NaN
(1 row)

SELECT '' AS five, FLOAT4_TBL.*;
 five |     f1      
------+-------------
      |           0
      |      1004.3
      |      -34.84
      | 1.23457e+20
      | 1.23457e-20
(5 rows)

SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE f.f1 <> '1004.3';
 four |     f1      
------+-------------
      |           0
      |      -34.84
      | 1.23457e+20
      | 1.23457e-20
(4 rows)

SELECT '' AS one, f.* FROM FLOAT4_TBL f WHERE f.f1 = '1004.3';
 one |   f1   
-----+--------
     | 1004.3
(1 row)

SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE '1004.3' > f.f1;
 three |     f1      
-------+-------------
       |           0
       |      -34.84
       | 1.23457e-20
(3 rows)

SELECT '' AS three, f.* FROM FLOAT4_TBL f WHERE  f.f1 < '1004.3';
 three |     f1      
-------+-------------
       |           0
       |      -34.84
       | 1.23457e-20
(3 rows)

SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1;
 four |     f1      
------+-------------
      |           0
      |      1004.3
      |      -34.84
      | 1.23457e-20
(4 rows)

SELECT '' AS four, f.* FROM FLOAT4_TBL f WHERE  f.f1 <= '1004.3';
 four |     f1      
------+-------------
      |           0
      |      1004.3
      |      -34.84
      | 1.23457e-20
(4 rows)

SELECT '' AS three, f.f1, f.f1 * '-10' AS x FROM FLOAT4_TBL f
   WHERE f.f1 > '0.0';
 three |     f1      |      x       
-------+-------------+--------------
       |      1004.3 |       -10043
       | 1.23457e+20 | -1.23457e+21
       | 1.23457e-20 | -1.23457e-19
(3 rows)

SELECT '' AS three, f.f1, f.f1 + '-10' AS x FROM FLOAT4_TBL f
   WHERE f.f1 > '0.0';
 three |     f1      |      x      
-------+-------------+-------------
       |      1004.3 |       994.3
       | 1.23457e+20 | 1.23457e+20
       | 1.23457e-20 |         -10
(3 rows)

SELECT '' AS three, f.f1, f.f1 / '-10' AS x FROM FLOAT4_TBL f
   WHERE f.f1 > '0.0';
 three |     f1      |      x       
-------+-------------+--------------
       |      1004.3 |      -100.43
       | 1.23457e+20 | -1.23457e+19
       | 1.23457e-20 | -1.23457e-21
(3 rows)

SELECT '' AS three, f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f
   WHERE f.f1 > '0.0';
 three |     f1      |      x      
-------+-------------+-------------
       |      1004.3 |      1014.3
       | 1.23457e+20 | 1.23457e+20
       | 1.23457e-20 |          10
(3 rows)

-- test divide by zero
SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f;
ERROR:  division by zero
SELECT '' AS five, FLOAT4_TBL.*;
 five |     f1      
------+-------------
      |           0
      |      1004.3
      |      -34.84
      | 1.23457e+20
      | 1.23457e-20
(5 rows)

-- test the unary float4abs operator 
SELECT '' AS five, f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
 five |     f1      |   abs_f1    
------+-------------+-------------
      |           0 |           0
      |      1004.3 |      1004.3
      |      -34.84 |       34.84
      | 1.23457e+20 | 1.23457e+20
      | 1.23457e-20 | 1.23457e-20
(5 rows)

UPDATE FLOAT4_TBL
   SET f1 = FLOAT4_TBL.f1 * '-1'
   WHERE FLOAT4_TBL.f1 > '0.0';
SELECT '' AS five, FLOAT4_TBL.*;
 five |      f1      
------+--------------
      |            0
      |       -34.84
      |      -1004.3
      | -1.23457e+20
      | -1.23457e-20
(5 rows)

