From 502d981ab450711f12e8e7cb1e0940144622cc0e Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 30 Jan 2021 07:57:14 +0300 Subject: [PATCH] Use BinaryArithmeticOverloadResolver::valid_on_float_arguments for lcm/gcd --- src/Functions/GCDLCMImpl.h | 4 +-- src/Functions/gcd.cpp | 2 +- src/Functions/lcm.cpp | 2 +- tests/queries/0_stateless/00515_gcd_lcm.sql | 28 +++++++++---------- .../0_stateless/01666_gcd_ubsan.reference | 2 +- tests/queries/0_stateless/01666_gcd_ubsan.sql | 2 +- .../0_stateless/01666_lcm_ubsan.reference | 2 +- tests/queries/0_stateless/01666_lcm_ubsan.sql | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Functions/GCDLCMImpl.h b/src/Functions/GCDLCMImpl.h index dffd91f8d6a..b83fe37abb6 100644 --- a/src/Functions/GCDLCMImpl.h +++ b/src/Functions/GCDLCMImpl.h @@ -21,7 +21,7 @@ namespace ErrorCodes } template -inline constexpr bool is_gcd_lcm_implemeted = !(is_big_int_v || std::is_floating_point_v); +inline constexpr bool is_gcd_lcm_implemeted = !is_big_int_v; template struct GCDLCMImpl @@ -33,7 +33,7 @@ struct GCDLCMImpl static inline std::enable_if_t, Result> apply(A, B) { - throw Exception(ErrorCodes::NOT_IMPLEMENTED, "{} is not implemented for big integers and floats", Name::name); + throw Exception(ErrorCodes::NOT_IMPLEMENTED, "{} is not implemented for big integers", Name::name); } template diff --git a/src/Functions/gcd.cpp b/src/Functions/gcd.cpp index 9cb53212c7f..52addfc66ed 100644 --- a/src/Functions/gcd.cpp +++ b/src/Functions/gcd.cpp @@ -23,7 +23,7 @@ struct GCDImpl : public GCDLCMImpl, NameGCD> } }; -using FunctionGCD = BinaryArithmeticOverloadResolver; +using FunctionGCD = BinaryArithmeticOverloadResolver; } diff --git a/src/Functions/lcm.cpp b/src/Functions/lcm.cpp index 5155a80e6cd..f46e11dfa17 100644 --- a/src/Functions/lcm.cpp +++ b/src/Functions/lcm.cpp @@ -54,7 +54,7 @@ struct LCMImpl : public GCDLCMImpl, NameLCM> } }; -using FunctionLCM = BinaryArithmeticOverloadResolver; +using FunctionLCM = BinaryArithmeticOverloadResolver; } diff --git a/tests/queries/0_stateless/00515_gcd_lcm.sql b/tests/queries/0_stateless/00515_gcd_lcm.sql index c3bf3275bb8..67fab1c9d59 100644 --- a/tests/queries/0_stateless/00515_gcd_lcm.sql +++ b/tests/queries/0_stateless/00515_gcd_lcm.sql @@ -24,18 +24,18 @@ select lcm(2147483647, 2147483646); select lcm(4611686011984936962, 2147483647); select lcm(-2147483648, 1); -- test gcd float -select gcd(1280.1, 1024.1); -- { serverError 48 } -select gcd(11.1, 121.1); -- { serverError 48 } -select gcd(-256.1, 64.1); -- { serverError 48 } -select gcd(1.1, 1.1); -- { serverError 48 } -select gcd(4.1, 2.1); -- { serverError 48 } -select gcd(15.1, 49.1); -- { serverError 48 } -select gcd(255.1, 254.1); -- { serverError 48 } +select gcd(1280.1, 1024.1); -- { serverError 43 } +select gcd(11.1, 121.1); -- { serverError 43 } +select gcd(-256.1, 64.1); -- { serverError 43 } +select gcd(1.1, 1.1); -- { serverError 43 } +select gcd(4.1, 2.1); -- { serverError 43 } +select gcd(15.1, 49.1); -- { serverError 43 } +select gcd(255.1, 254.1); -- { serverError 43 } -- test lcm float -select lcm(1280.1, 1024.1); -- { serverError 48 } -select lcm(11.1, 121.1); -- { serverError 48 } -select lcm(-256.1, 64.1); -- { serverError 48 } -select lcm(1.1, 1.1); -- { serverError 48 } -select lcm(4.1, 2.1); -- { serverError 48 } -select lcm(15.1, 49.1); -- { serverError 48 } -select lcm(255.1, 254.1); -- { serverError 48 } +select lcm(1280.1, 1024.1); -- { serverError 43 } +select lcm(11.1, 121.1); -- { serverError 43 } +select lcm(-256.1, 64.1); -- { serverError 43 } +select lcm(1.1, 1.1); -- { serverError 43 } +select lcm(4.1, 2.1); -- { serverError 43 } +select lcm(15.1, 49.1); -- { serverError 43 } +select lcm(255.1, 254.1); -- { serverError 43 } diff --git a/tests/queries/0_stateless/01666_gcd_ubsan.reference b/tests/queries/0_stateless/01666_gcd_ubsan.reference index 2500ef1deae..af041bdcbde 100644 --- a/tests/queries/0_stateless/01666_gcd_ubsan.reference +++ b/tests/queries/0_stateless/01666_gcd_ubsan.reference @@ -4,7 +4,7 @@ SELECT gcd(9223372036854775808, -9223372036854775807); -- { serverError 407 } SELECT gcd(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT gcd(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT gcd(9223372036854775808, -1); -- { serverError 407 } -SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 48 } +SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 43 } SELECT lcm(toInt128(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720')); diff --git a/tests/queries/0_stateless/01666_gcd_ubsan.sql b/tests/queries/0_stateless/01666_gcd_ubsan.sql index bde2b624cc0..a1f501cda0b 100644 --- a/tests/queries/0_stateless/01666_gcd_ubsan.sql +++ b/tests/queries/0_stateless/01666_gcd_ubsan.sql @@ -4,7 +4,7 @@ SELECT gcd(9223372036854775808, -9223372036854775807); -- { serverError 407 } SELECT gcd(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT gcd(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT gcd(9223372036854775808, -1); -- { serverError 407 } -SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 48 } +SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 43 } SELECT lcm(toInt128(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720')); diff --git a/tests/queries/0_stateless/01666_lcm_ubsan.reference b/tests/queries/0_stateless/01666_lcm_ubsan.reference index ed9a6aed42b..d8ed13191d3 100644 --- a/tests/queries/0_stateless/01666_lcm_ubsan.reference +++ b/tests/queries/0_stateless/01666_lcm_ubsan.reference @@ -4,7 +4,7 @@ SELECT lcm(9223372036854775808, -9223372036854775807); -- { serverError 407 } SELECT lcm(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT lcm(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT lcm(9223372036854775808, -1); -- { serverError 407 } -SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 48 } +SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 43 } SELECT lcm(toInt128(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720')); diff --git a/tests/queries/0_stateless/01666_lcm_ubsan.sql b/tests/queries/0_stateless/01666_lcm_ubsan.sql index 5cc3546e941..b3b869c80ed 100644 --- a/tests/queries/0_stateless/01666_lcm_ubsan.sql +++ b/tests/queries/0_stateless/01666_lcm_ubsan.sql @@ -4,7 +4,7 @@ SELECT lcm(9223372036854775808, -9223372036854775807); -- { serverError 407 } SELECT lcm(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT lcm(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT lcm(9223372036854775808, -1); -- { serverError 407 } -SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 48 } +SELECT lcm(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728); -- { serverError 43 } SELECT lcm(toInt128(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720'));