From d84bd5bb915b2b569f4cfc8c6cab897fb1734f23 Mon Sep 17 00:00:00 2001 From: gengliqi Date: Mon, 25 Nov 2024 15:28:17 +0800 Subject: [PATCH 1/2] fix radian Signed-off-by: gengliqi --- pkg/expression/builtin_math.go | 2 +- pkg/expression/builtin_math_test.go | 2 ++ pkg/expression/builtin_math_vec.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/expression/builtin_math.go b/pkg/expression/builtin_math.go index a701d7348cda9..40d248c6e6a05 100644 --- a/pkg/expression/builtin_math.go +++ b/pkg/expression/builtin_math.go @@ -1821,7 +1821,7 @@ func (b *builtinRadiansSig) evalReal(ctx EvalContext, row chunk.Row) (float64, b if isNull || err != nil { return 0, isNull, err } - return x * math.Pi / 180, false, nil + return x * (math.Pi / 180), false, nil } type sinFunctionClass struct { diff --git a/pkg/expression/builtin_math_test.go b/pkg/expression/builtin_math_test.go index d78ed2c5f0f7e..85501faebb07d 100644 --- a/pkg/expression/builtin_math_test.go +++ b/pkg/expression/builtin_math_test.go @@ -756,6 +756,8 @@ func TestRadians(t *testing.T) { {float64(180), float64(math.Pi)}, {-360, -2 * float64(math.Pi)}, {"180", float64(math.Pi)}, + {float64(1.0e308), float64(1.7453292519943295e306)}, + {float64(23), float64(0.4014257279586958)}, } Dtbl := tblToDtbl(tbl) diff --git a/pkg/expression/builtin_math_vec.go b/pkg/expression/builtin_math_vec.go index 182404fa43787..ddac91f27a8d5 100644 --- a/pkg/expression/builtin_math_vec.go +++ b/pkg/expression/builtin_math_vec.go @@ -314,7 +314,7 @@ func (b *builtinRadiansSig) vecEvalReal(ctx EvalContext, input *chunk.Chunk, res if result.IsNull(i) { continue } - f64s[i] = f64s[i] * math.Pi / 180 + f64s[i] = f64s[i] * (math.Pi / 180) } return nil } From b786a753f35a6dead3b03b57ab014c9003256bd0 Mon Sep 17 00:00:00 2001 From: gengliqi Date: Mon, 25 Nov 2024 16:36:21 +0800 Subject: [PATCH 2/2] update integration test result Signed-off-by: gengliqi --- tests/integrationtest/r/expression/builtin.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrationtest/r/expression/builtin.result b/tests/integrationtest/r/expression/builtin.result index ed7728089a1be..03e1000b0abab 100644 --- a/tests/integrationtest/r/expression/builtin.result +++ b/tests/integrationtest/r/expression/builtin.result @@ -520,7 +520,7 @@ crc32(0) crc32(-0) crc32('0') crc32('abc') crc32('ABC') crc32(NULL) crc32('') cr 4108050209 4108050209 4108050209 891568578 2743272264 NULL 0 62177901 SELECT radians(1.0), radians(pi()), radians(pi()/2), radians(180), radians(1.009); radians(1.0) radians(pi()) radians(pi()/2) radians(180) radians(1.009) -0.017453292519943295 0.05483113556160754 0.02741556778080377 3.141592653589793 0.01761037215262278 +0.017453292519943295 0.05483113556160755 0.027415567780803774 3.141592653589793 0.01761037215262278 drop table if exists t; create table t(a int); insert into t values(1),(2),(3);