Skip to content

Commit 3fd908a

Browse files
authored
expression: fix wrong calculation order of radians (pingcap#57672) (pingcap#57686)
close pingcap#57661, close pingcap#57671
1 parent 8603039 commit 3fd908a

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

pkg/expression/builtin_math.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ func (b *builtinRadiansSig) evalReal(row chunk.Row) (float64, bool, error) {
18181818
if isNull || err != nil {
18191819
return 0, isNull, err
18201820
}
1821-
return x * math.Pi / 180, false, nil
1821+
return x * (math.Pi / 180), false, nil
18221822
}
18231823

18241824
type sinFunctionClass struct {

pkg/expression/builtin_math_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ func TestRadians(t *testing.T) {
751751
{float64(180), float64(math.Pi)},
752752
{-360, -2 * float64(math.Pi)},
753753
{"180", float64(math.Pi)},
754+
{float64(1.0e308), float64(1.7453292519943295e306)},
755+
{float64(23), float64(0.4014257279586958)},
754756
}
755757

756758
Dtbl := tblToDtbl(tbl)

pkg/expression/builtin_math_vec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (b *builtinRadiansSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column
310310
if result.IsNull(i) {
311311
continue
312312
}
313-
f64s[i] = f64s[i] * math.Pi / 180
313+
f64s[i] = f64s[i] * (math.Pi / 180)
314314
}
315315
return nil
316316
}

tests/integrationtest/r/expression/builtin.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ crc32(0) crc32(-0) crc32('0') crc32('abc') crc32('ABC') crc32(NULL) crc32('') cr
520520
4108050209 4108050209 4108050209 891568578 2743272264 NULL 0 62177901
521521
SELECT radians(1.0), radians(pi()), radians(pi()/2), radians(180), radians(1.009);
522522
radians(1.0) radians(pi()) radians(pi()/2) radians(180) radians(1.009)
523-
0.017453292519943295 0.05483113556160754 0.02741556778080377 3.141592653589793 0.01761037215262278
523+
0.017453292519943295 0.05483113556160755 0.027415567780803774 3.141592653589793 0.01761037215262278
524524
drop table if exists t;
525525
create table t(a int);
526526
insert into t values(1),(2),(3);

0 commit comments

Comments
 (0)