Skip to content

YQL-17615: fixed formatting of float4 in pgrun #1339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions ydb/library/yql/tests/postgresql/cases/float4.out
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,6 @@ SELECT f.f1, f.f1 * '-10' AS x FROM FLOAT4_TBL f
1.2345679e-20 | -1.2345678e-19
(3 rows)

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

SELECT f.f1, f.f1 / '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
f1 | x
Expand Down
2 changes: 0 additions & 2 deletions ydb/library/yql/tests/postgresql/cases/float4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ SELECT f.* FROM FLOAT4_TBL f WHERE '1004.3' >= f.f1;
SELECT f.* FROM FLOAT4_TBL f WHERE f.f1 <= '1004.3';
SELECT f.f1, f.f1 * '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
SELECT f.f1, f.f1 + '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
SELECT f.f1, f.f1 / '-10' AS x FROM FLOAT4_TBL f
WHERE f.f1 > '0.0';
SELECT f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f
Expand Down
88 changes: 71 additions & 17 deletions ydb/library/yql/tests/postgresql/cases/float8.out
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,6 @@ SELECT f.f1, f.f1 + '-10' AS x
1.2345678901234e-200 | -10
(3 rows)

SELECT f.f1, f.f1 / '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
f1 | x
----------------------+-----------------------
1004.3 | -100.42999999999999
1.2345678901234e+200 | -1.2345678901234e+199
1.2345678901234e-200 | -1.2345678901234e-201
(3 rows)

SELECT f.f1, f.f1 - '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
Expand All @@ -236,13 +226,6 @@ SELECT f.f1, f.f1 - '-10' AS x
1.2345678901234e-200 | 10
(3 rows)

SELECT f.f1 ^ '2.0' AS square_f1
FROM FLOAT8_TBL f where f.f1 = '1004.3';
square_f1
--------------------
1008618.4899999999
(1 row)

-- absolute value
SELECT f.f1, @f.f1 AS abs_f1
FROM FLOAT8_TBL f;
Expand Down Expand Up @@ -294,6 +277,16 @@ SELECT |/ float8 '64' AS eight;
8
(1 row)

SELECT f.f1, |/f.f1 AS sqrt_f1
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
f1 | sqrt_f1
----------------------+-----------------------
1004.3 | 31.6906926399535
1.2345678901234e+200 | 1.11111110611109e+100
1.2345678901234e-200 | 1.11111110611109e-100
(3 rows)

-- power
SELECT power(float8 '144', float8 '0.5');
power
Expand Down Expand Up @@ -493,13 +486,41 @@ SELECT power(float8 '-inf', float8 '-inf');
0
(1 row)

-- take exp of ln(f.f1)
SELECT f.f1, exp(ln(f.f1)) AS exp_ln_f1
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
f1 | exp_ln_f1
----------------------+-----------------------
1004.3 | 1004.3
1.2345678901234e+200 | 1.23456789012338e+200
1.2345678901234e-200 | 1.23456789012339e-200
(3 rows)

-- check edge cases for exp
SELECT exp('inf'::float8), exp('-inf'::float8), exp('nan'::float8);
exp | exp | exp
----------+-----+-----
Infinity | 0 | NaN
(1 row)

-- cube root
SELECT ||/ float8 '27' AS three;
three
-------
3
(1 row)

SELECT f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
f1 | cbrt_f1
----------------------+----------------------
0 | 0
1004.3 | 10.014312837827
-34.84 | -3.26607421344208
1.2345678901234e+200 | 4.97933859234765e+66
1.2345678901234e-200 | 2.3112042409018e-67
(5 rows)

SELECT * FROM FLOAT8_TBL;
f1
----------------------
Expand All @@ -526,12 +547,45 @@ SELECT ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
ERROR: cannot take logarithm of a negative number
SELECT f.f1 / '0.0' from FLOAT8_TBL f;
ERROR: division by zero
-- hyperbolic functions
-- we run these with extra_float_digits = 0 too, since different platforms
-- tend to produce results that vary in the last place.
SELECT sinh(float8 '1');
sinh
-----------------
1.1752011936438
(1 row)

SELECT cosh(float8 '1');
cosh
------------------
1.54308063481524
(1 row)

SELECT tanh(float8 '1');
tanh
-------------------
0.761594155955765
(1 row)

SELECT asinh(float8 '1');
asinh
-------------------
0.881373587019543
(1 row)

SELECT acosh(float8 '2');
acosh
------------------
1.31695789692482
(1 row)

SELECT atanh(float8 '0.5');
atanh
-------------------
0.549306144334055
(1 row)

-- test Inf/NaN cases for hyperbolic functions
SELECT sinh(float8 'infinity');
sinh
Expand Down
23 changes: 18 additions & 5 deletions ydb/library/yql/tests/postgresql/cases/float8.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ SELECT f.f1, f.f1 * '-10' AS x
SELECT f.f1, f.f1 + '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
SELECT f.f1, f.f1 / '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
SELECT f.f1, f.f1 - '-10' AS x
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
SELECT f.f1 ^ '2.0' AS square_f1
FROM FLOAT8_TBL f where f.f1 = '1004.3';
-- absolute value
SELECT f.f1, @f.f1 AS abs_f1
FROM FLOAT8_TBL f;
Expand All @@ -72,6 +67,9 @@ SET extra_float_digits = 0;
-- square root
SELECT sqrt(float8 '64') AS eight;
SELECT |/ float8 '64' AS eight;
SELECT f.f1, |/f.f1 AS sqrt_f1
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
-- power
SELECT power(float8 '144', float8 '0.5');
SELECT power(float8 'NaN', float8 '0.5');
Expand Down Expand Up @@ -109,16 +107,31 @@ SELECT power(float8 '-inf', float8 '3');
SELECT power(float8 '-inf', float8 '3.5');
SELECT power(float8 '-inf', float8 'inf');
SELECT power(float8 '-inf', float8 '-inf');
-- take exp of ln(f.f1)
SELECT f.f1, exp(ln(f.f1)) AS exp_ln_f1
FROM FLOAT8_TBL f
WHERE f.f1 > '0.0';
-- check edge cases for exp
SELECT exp('inf'::float8), exp('-inf'::float8), exp('nan'::float8);
-- cube root
SELECT ||/ float8 '27' AS three;
SELECT f.f1, ||/f.f1 AS cbrt_f1 FROM FLOAT8_TBL f;
SELECT * FROM FLOAT8_TBL;
SELECT f.f1 * '1e200' from FLOAT8_TBL f;
SELECT f.f1 ^ '1e200' from FLOAT8_TBL f;
SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
SELECT ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
SELECT ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
SELECT f.f1 / '0.0' from FLOAT8_TBL f;
-- hyperbolic functions
-- we run these with extra_float_digits = 0 too, since different platforms
-- tend to produce results that vary in the last place.
SELECT sinh(float8 '1');
SELECT cosh(float8 '1');
SELECT tanh(float8 '1');
SELECT asinh(float8 '1');
SELECT acosh(float8 '2');
SELECT atanh(float8 '0.5');
-- test Inf/NaN cases for hyperbolic functions
SELECT sinh(float8 'infinity');
SELECT sinh(float8 '-infinity');
Expand Down
4 changes: 2 additions & 2 deletions ydb/library/yql/tools/pgrun/pgrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,13 @@ const TString FormatFloat(const TString& value, std::function<TString(const TStr
inline const TString FormatFloat4(const TString& value)
{
return FormatFloat(value,
[] (const TString& val) { return TString(fmt::format("{0}", std::stof(val))); });
[] (const TString& val) { return TString(fmt::format("{:.8g}", std::stof(val))); });
}

inline const TString FormatFloat8(const TString& value)
{
return FormatFloat(value,
[] (const TString& val) { return TString(fmt::format("{0}", std::stod(val))); });
[] (const TString& val) { return TString(fmt::format("{:.15g}", std::stod(val))); });
}

inline const TString FormatTransparent(const TString& value)
Expand Down