Use BinaryArithmeticOverloadResolver::valid_on_float_arguments for lcm/gcd

This commit is contained in:
Azat Khuzhin 2021-01-30 07:57:14 +03:00
parent 7da4083237
commit 502d981ab4
8 changed files with 22 additions and 22 deletions

View File

@ -21,7 +21,7 @@ namespace ErrorCodes
} }
template <class T> template <class T>
inline constexpr bool is_gcd_lcm_implemeted = !(is_big_int_v<T> || std::is_floating_point_v<T>); inline constexpr bool is_gcd_lcm_implemeted = !is_big_int_v<T>;
template <typename A, typename B, typename Impl, typename Name> template <typename A, typename B, typename Impl, typename Name>
struct GCDLCMImpl struct GCDLCMImpl
@ -33,7 +33,7 @@ struct GCDLCMImpl
static inline std::enable_if_t<!is_gcd_lcm_implemeted<Result>, Result> static inline std::enable_if_t<!is_gcd_lcm_implemeted<Result>, Result>
apply(A, B) 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 <typename Result = ResultType> template <typename Result = ResultType>

View File

@ -23,7 +23,7 @@ struct GCDImpl : public GCDLCMImpl<A, B, GCDImpl<A, B>, NameGCD>
} }
}; };
using FunctionGCD = BinaryArithmeticOverloadResolver<GCDImpl, NameGCD, false>; using FunctionGCD = BinaryArithmeticOverloadResolver<GCDImpl, NameGCD, false, false>;
} }

View File

@ -54,7 +54,7 @@ struct LCMImpl : public GCDLCMImpl<A, B, LCMImpl<A, B>, NameLCM>
} }
}; };
using FunctionLCM = BinaryArithmeticOverloadResolver<LCMImpl, NameLCM, false>; using FunctionLCM = BinaryArithmeticOverloadResolver<LCMImpl, NameLCM, false, false>;
} }

View File

@ -24,18 +24,18 @@ select lcm(2147483647, 2147483646);
select lcm(4611686011984936962, 2147483647); select lcm(4611686011984936962, 2147483647);
select lcm(-2147483648, 1); select lcm(-2147483648, 1);
-- test gcd float -- test gcd float
select gcd(1280.1, 1024.1); -- { serverError 48 } select gcd(1280.1, 1024.1); -- { serverError 43 }
select gcd(11.1, 121.1); -- { serverError 48 } select gcd(11.1, 121.1); -- { serverError 43 }
select gcd(-256.1, 64.1); -- { serverError 48 } select gcd(-256.1, 64.1); -- { serverError 43 }
select gcd(1.1, 1.1); -- { serverError 48 } select gcd(1.1, 1.1); -- { serverError 43 }
select gcd(4.1, 2.1); -- { serverError 48 } select gcd(4.1, 2.1); -- { serverError 43 }
select gcd(15.1, 49.1); -- { serverError 48 } select gcd(15.1, 49.1); -- { serverError 43 }
select gcd(255.1, 254.1); -- { serverError 48 } select gcd(255.1, 254.1); -- { serverError 43 }
-- test lcm float -- test lcm float
select lcm(1280.1, 1024.1); -- { serverError 48 } select lcm(1280.1, 1024.1); -- { serverError 43 }
select lcm(11.1, 121.1); -- { serverError 48 } select lcm(11.1, 121.1); -- { serverError 43 }
select lcm(-256.1, 64.1); -- { serverError 48 } select lcm(-256.1, 64.1); -- { serverError 43 }
select lcm(1.1, 1.1); -- { serverError 48 } select lcm(1.1, 1.1); -- { serverError 43 }
select lcm(4.1, 2.1); -- { serverError 48 } select lcm(4.1, 2.1); -- { serverError 43 }
select lcm(15.1, 49.1); -- { serverError 48 } select lcm(15.1, 49.1); -- { serverError 43 }
select lcm(255.1, 254.1); -- { serverError 48 } select lcm(255.1, 254.1); -- { serverError 43 }

View File

@ -4,7 +4,7 @@ SELECT gcd(9223372036854775808, -9223372036854775807); -- { serverError 407 }
SELECT gcd(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT gcd(-9223372036854775808, 9223372036854775807); -- { serverError 407 }
SELECT gcd(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT gcd(-9223372036854775807, 9223372036854775808); -- { serverError 407 }
SELECT gcd(9223372036854775808, -1); -- { 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(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 }
SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 }
SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720')); SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720'));

View File

@ -4,7 +4,7 @@ SELECT gcd(9223372036854775808, -9223372036854775807); -- { serverError 407 }
SELECT gcd(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT gcd(-9223372036854775808, 9223372036854775807); -- { serverError 407 }
SELECT gcd(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT gcd(-9223372036854775807, 9223372036854775808); -- { serverError 407 }
SELECT gcd(9223372036854775808, -1); -- { 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(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 }
SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 }
SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720')); SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720'));

View File

@ -4,7 +4,7 @@ SELECT lcm(9223372036854775808, -9223372036854775807); -- { serverError 407 }
SELECT lcm(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT lcm(-9223372036854775808, 9223372036854775807); -- { serverError 407 }
SELECT lcm(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT lcm(-9223372036854775807, 9223372036854775808); -- { serverError 407 }
SELECT lcm(9223372036854775808, -1); -- { 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(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 }
SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 }
SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720')); SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720'));

View File

@ -4,7 +4,7 @@ SELECT lcm(9223372036854775808, -9223372036854775807); -- { serverError 407 }
SELECT lcm(-9223372036854775808, 9223372036854775807); -- { serverError 407 } SELECT lcm(-9223372036854775808, 9223372036854775807); -- { serverError 407 }
SELECT lcm(-9223372036854775807, 9223372036854775808); -- { serverError 407 } SELECT lcm(-9223372036854775807, 9223372036854775808); -- { serverError 407 }
SELECT lcm(9223372036854775808, -1); -- { 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(-170141183460469231731687303715884105728), toInt128(-170141183460469231731687303715884105728)); -- { serverError 407 }
SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 } SELECT lcm(toInt128(-170141183460469231731687303715884105720), toInt128(-170141183460469231731687303715884105720)); -- { serverError 407 }
SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720')); SELECT lcm(toInt128('-170141183460469231731687303715884105720'), toInt128('-170141183460469231731687303715884105720'));