Skip to content

Commit efb0a46

Browse files
committed
Fix signatures of the square root methods
1 parent e0e3e2a commit efb0a46

6 files changed

Lines changed: 16 additions & 48 deletions

File tree

python/src/softfloatpy/_core.pyi

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,15 +1323,11 @@ class Float16:
13231323
"""
13241324
...
13251325

1326-
@classmethod
1327-
def sqrt(cls, x: Self) -> Self:
1326+
def sqrt(self) -> Self:
13281327
"""Calculates a square root of the IEEE 754 binary16 floating point.
13291328
13301329
The result is the same as that of :func:`f16_sqrt()`.
13311330
1332-
Args:
1333-
x: The floating point whose square root is to be calculated.
1334-
13351331
Returns:
13361332
The resulted number (``sqrt(x)``).
13371333
@@ -1836,15 +1832,11 @@ class Float32:
18361832
"""
18371833
...
18381834

1839-
@classmethod
1840-
def sqrt(cls, x: Self) -> Self:
1835+
def sqrt(self) -> Self:
18411836
"""Calculates a square root of the IEEE 754 binary32 floating point.
18421837
18431838
The result is the same as that of :func:`f32_sqrt()`.
18441839
1845-
Args:
1846-
x: The floating point whose square root is to be calculated.
1847-
18481840
Returns:
18491841
The resulted number (``sqrt(x)``).
18501842
@@ -2338,15 +2330,11 @@ class Float64:
23382330
"""
23392331
...
23402332

2341-
@classmethod
2342-
def sqrt(cls, x: Self) -> Self:
2333+
def sqrt(self) -> Self:
23432334
"""Calculates a square root of the IEEE 754 binary64 floating point.
23442335
23452336
The result is the same as that of :func:`f64_sqrt()`.
23462337
2347-
Args:
2348-
x: The floating point whose square root is to be calculated.
2349-
23502338
Returns:
23512339
The resulted number (``sqrt(x)``).
23522340
@@ -2852,15 +2840,11 @@ class Float128:
28522840
"""
28532841
...
28542842

2855-
@classmethod
2856-
def sqrt(cls, x: Self) -> Self:
2843+
def sqrt(self) -> Self:
28572844
"""Calculates a square root of the IEEE 754 binary128 floating point.
28582845
28592846
The result is the same as that of :func:`f128_sqrt()`.
28602847
2861-
Args:
2862-
x: The floating point whose square root is to be calculated.
2863-
28642848
Returns:
28652849
The resulted number (``sqrt(x)``).
28662850

python/src/softfloatpy/_core.pyx

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,20 +1546,16 @@ cdef class Float16:
15461546
"""
15471547
return f16_rem(x, y)
15481548

1549-
@classmethod
1550-
def sqrt(cls, Float16 x) -> Float16:
1549+
cpdef Float16 sqrt(self):
15511550
"""Calculates a square root of the IEEE 754 binary16 floating point.
15521551
15531552
The result is the same as that of :func:`f16_sqrt()`.
15541553
1555-
Args:
1556-
x: The floating point whose square root is to be calculated.
1557-
15581554
Returns:
15591555
The resulted number (``sqrt(x)``).
15601556
15611557
"""
1562-
return f16_sqrt(x)
1558+
return f16_sqrt(self)
15631559

15641560
@classmethod
15651561
def eq(cls, Float16 x, Float16 y) -> bool:
@@ -2092,20 +2088,16 @@ cdef class Float32:
20922088
"""
20932089
return f32_rem(x, y)
20942090

2095-
@classmethod
2096-
def sqrt(cls, Float32 x) -> Float32:
2091+
cpdef Float32 sqrt(self):
20972092
"""Calculates a square root of the IEEE 754 binary32 floating point.
20982093
20992094
The result is the same as that of :func:`f32_sqrt()`.
21002095
2101-
Args:
2102-
x: The floating point whose square root is to be calculated.
2103-
21042096
Returns:
21052097
The resulted number (``sqrt(x)``).
21062098
21072099
"""
2108-
return f32_sqrt(x)
2100+
return f32_sqrt(self)
21092101

21102102
@classmethod
21112103
def eq(cls, Float32 x, Float32 y) -> bool:
@@ -2633,20 +2625,16 @@ cdef class Float64:
26332625
"""
26342626
return f64_rem(x, y)
26352627

2636-
@classmethod
2637-
def sqrt(cls, Float64 x) -> Float64:
2628+
cpdef Float64 sqrt(self):
26382629
"""Calculates a square root of the IEEE 754 binary64 floating point.
26392630
26402631
The result is the same as that of :func:`f64_sqrt()`.
26412632
2642-
Args:
2643-
x: The floating point whose square root is to be calculated.
2644-
26452633
Returns:
26462634
The resulted number (``sqrt(x)``).
26472635
26482636
"""
2649-
return f64_sqrt(x)
2637+
return f64_sqrt(self)
26502638

26512639
@classmethod
26522640
def eq(cls, Float64 x, Float64 y) -> bool:
@@ -3210,20 +3198,16 @@ cdef class Float128:
32103198
"""
32113199
return f128_rem(x, y)
32123200

3213-
@classmethod
3214-
def sqrt(cls, Float128 x) -> Float128:
3201+
cpdef Float128 sqrt(self):
32153202
"""Calculates a square root of the IEEE 754 binary128 floating point.
32163203
32173204
The result is the same as that of :func:`f128_sqrt()`.
32183205
3219-
Args:
3220-
x: The floating point whose square root is to be calculated.
3221-
32223206
Returns:
32233207
The resulted number (``sqrt(x)``).
32243208
32253209
"""
3226-
return f128_sqrt(x)
3210+
return f128_sqrt(self)
32273211

32283212
@classmethod
32293213
def eq(cls, Float128 x, Float128 y) -> bool:

python/tests/softfloatpy/test_float128.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_f128_sqrt() -> None:
165165
x: float = 2.25
166166
o: sf.Float128 = sf.Float128.from_float(x)
167167
assert sf.f128_sqrt(o).to_float() == math.sqrt(x)
168-
assert sf.f128_sqrt(o).to_bytes() == sf.Float128.sqrt(o).to_bytes()
168+
assert sf.f128_sqrt(o).to_bytes() == o.sqrt().to_bytes()
169169

170170

171171
def test_f128_eq() -> None:

python/tests/softfloatpy/test_float16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_f16_sqrt() -> None:
165165
x: float = 2.25
166166
o: sf.Float16 = sf.Float16.from_float(x)
167167
assert sf.f16_sqrt(o).to_float() == math.sqrt(x)
168-
assert sf.f16_sqrt(o).to_bytes() == sf.Float16.sqrt(o).to_bytes()
168+
assert sf.f16_sqrt(o).to_bytes() == o.sqrt().to_bytes()
169169

170170

171171
def test_f16_eq() -> None:

python/tests/softfloatpy/test_float32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_f32_sqrt() -> None:
171171
x: float = 2.25
172172
o: sf.Float32 = sf.Float32.from_float(x)
173173
assert sf.f32_sqrt(o).to_float() == math.sqrt(x)
174-
assert sf.f32_sqrt(o).to_bytes() == sf.Float32.sqrt(o).to_bytes()
174+
assert sf.f32_sqrt(o).to_bytes() == o.sqrt().to_bytes()
175175

176176

177177
def test_f32_eq() -> None:

python/tests/softfloatpy/test_float64.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_f64_sqrt() -> None:
165165
x: float = 2.25
166166
o: sf.Float64 = sf.Float64.from_float(x)
167167
assert sf.f64_sqrt(o).to_float() == math.sqrt(x)
168-
assert sf.f64_sqrt(o).to_bytes() == sf.Float64.sqrt(o).to_bytes()
168+
assert sf.f64_sqrt(o).to_bytes() == o.sqrt().to_bytes()
169169

170170

171171
def test_f64_eq() -> None:

0 commit comments

Comments
 (0)