From a9d486579def7734cf47f3a19154e33383e42e45 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Mon, 11 Mar 2024 16:57:19 -0400 Subject: [PATCH 1/2] Make 'proc sgn' and 'proc bigint.sgn' overloads unstable --- Signed-off-by: Michael Ferguson --- modules/standard/AutoMath.chpl | 4 ++++ modules/standard/BigInteger.chpl | 1 + 2 files changed, 5 insertions(+) diff --git a/modules/standard/AutoMath.chpl b/modules/standard/AutoMath.chpl index 9dc358668bb1..b89a59b66ca8 100644 --- a/modules/standard/AutoMath.chpl +++ b/modules/standard/AutoMath.chpl @@ -580,24 +580,28 @@ module AutoMath { /* Returns the signum function of the integer argument `x`: 1 if positive, -1 if negative, 0 if zero. */ + @unstable("sgn is unstable and may change its name and return type in the future") inline proc sgn(x : int(?w)): int(8) do return ((x > 0) : int(8) - (x < 0) : int(8)) : int(8); /* Returns the signum function of the unsigned integer argument `x`: 1 if positive, -1 if negative, 0 if zero. */ + @unstable("sgn is unstable and may change its name and return type in the future") inline proc sgn(x : uint(?w)): uint(8) do return (x > 0) : uint(8); /* Returns the signum function of the integer param argument `x`: 1 if positive, -1 if negative, 0 if zero. */ + @unstable("sgn is unstable and may change its name and return type in the future") proc sgn(param x : integral) param do return if x > 0 then 1 else if x == 0 then 0 else -1; /* Returns the signum function of the real argument `x`: 1 if positive, -1 if negative, 0 if zero. */ + @unstable("sgn is unstable and may change its name and return type in the future") inline proc sgn(x : real(?w)): int(8) do return ((x > 0.0) : int(8) - (x < 0.0) : int(8)) : int(8); diff --git a/modules/standard/BigInteger.chpl b/modules/standard/BigInteger.chpl index 713a3fc43bed..ea4bc93e353b 100644 --- a/modules/standard/BigInteger.chpl +++ b/modules/standard/BigInteger.chpl @@ -3686,6 +3686,7 @@ module BigInteger { :proc:`GMP.mpz_sgn` and `mpz_sgn `_. */ + @unstable("bigint.sgn is unstable and may change its name and return type in the future") proc bigint.sgn() : int { const this_ = this.localize(); var ret : c_int; From 4f7cbb35196a0bc805a20dc1f6d64f633e259e75 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Mon, 11 Mar 2024 17:08:53 -0400 Subject: [PATCH 2/2] Add tests for unstable proc sgn / bigint.sgn --- Signed-off-by: Michael Ferguson --- .../BigInteger/unstable-sgn-bigint.chpl | 5 ++ .../BigInteger/unstable-sgn-bigint.good | 1 + test/unstable/unstable-sgn.chpl | 48 +++++++++++++++++++ test/unstable/unstable-sgn.good | 20 ++++++++ 4 files changed, 74 insertions(+) create mode 100644 test/unstable/BigInteger/unstable-sgn-bigint.chpl create mode 100644 test/unstable/BigInteger/unstable-sgn-bigint.good create mode 100644 test/unstable/unstable-sgn.chpl create mode 100644 test/unstable/unstable-sgn.good diff --git a/test/unstable/BigInteger/unstable-sgn-bigint.chpl b/test/unstable/BigInteger/unstable-sgn-bigint.chpl new file mode 100644 index 000000000000..77dacdf284dd --- /dev/null +++ b/test/unstable/BigInteger/unstable-sgn-bigint.chpl @@ -0,0 +1,5 @@ +use BigInteger; + +// bigint +var b = new bigint(1); +assert(b.sgn() == 1); diff --git a/test/unstable/BigInteger/unstable-sgn-bigint.good b/test/unstable/BigInteger/unstable-sgn-bigint.good new file mode 100644 index 000000000000..feaef9b2de3e --- /dev/null +++ b/test/unstable/BigInteger/unstable-sgn-bigint.good @@ -0,0 +1 @@ +unstable-sgn-bigint.chpl:5: warning: bigint.sgn is unstable and may change its name and return type in the future diff --git a/test/unstable/unstable-sgn.chpl b/test/unstable/unstable-sgn.chpl new file mode 100644 index 000000000000..33a3d5aa13d3 --- /dev/null +++ b/test/unstable/unstable-sgn.chpl @@ -0,0 +1,48 @@ +// non-param numeric types +var i8: int(8) = 1; +var i16: int(16) = 1; +var i32: int(32) = 1; +var i64: int(64) = 1; +assert(sgn(i8) == 1); +assert(sgn(i16) == 1); +assert(sgn(i32) == 1); +assert(sgn(i64) == 1); + +var u8: uint(8) = 1; +var u16: uint(16) = 1; +var u32: uint(32) = 1; +var u64: uint(64) = 1; +assert(sgn(u8) == 1); +assert(sgn(u16) == 1); +assert(sgn(u32) == 1); +assert(sgn(u64) == 1); + +var r32: real(32) = 1; +var r64: real(64) = 1; +assert(sgn(r32) == 1); +assert(sgn(r64) == 1); + + +// param numeric types +param pi8: int(8) = 1; +param pi16: int(16) = 1; +param pi32: int(32) = 1; +param pi64: int(64) = 1; +assert(sgn(pi8) == 1); +assert(sgn(pi16) == 1); +assert(sgn(pi32) == 1); +assert(sgn(pi64) == 1); + +param pu8: uint(8) = 1; +param pu16: uint(16) = 1; +param pu32: uint(32) = 1; +param pu64: uint(64) = 1; +assert(sgn(pu8) == 1); +assert(sgn(pu16) == 1); +assert(sgn(pu32) == 1); +assert(sgn(pu64) == 1); + +param pr32: real(32) = 1; +param pr64: real(64) = 1; +assert(sgn(pr32) == 1); +assert(sgn(pr64) == 1); diff --git a/test/unstable/unstable-sgn.good b/test/unstable/unstable-sgn.good new file mode 100644 index 000000000000..0d2ee1482742 --- /dev/null +++ b/test/unstable/unstable-sgn.good @@ -0,0 +1,20 @@ +unstable-sgn.chpl:6: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:7: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:8: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:9: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:15: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:16: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:17: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:18: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:22: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:23: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:31: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:32: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:33: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:34: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:40: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:41: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:42: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:43: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:47: warning: sgn is unstable and may change its name and return type in the future +unstable-sgn.chpl:48: warning: sgn is unstable and may change its name and return type in the future