Skip to content

Commit 376948d

Browse files
committed
Add methods and functions to negate floating points
Improper negation of NaN is fixed.
1 parent 2ac43d9 commit 376948d

7 files changed

Lines changed: 233 additions & 6 deletions

File tree

python/src/softfloatpy/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"f16_to_f64",
6565
"f16_to_f128",
6666
"f16_round_to_int",
67+
"f16_neg",
6768
"f16_add",
6869
"f16_sub",
6970
"f16_mul",
@@ -89,6 +90,7 @@
8990
"f32_to_f64",
9091
"f32_to_f128",
9192
"f32_round_to_int",
93+
"f32_neg",
9294
"f32_add",
9395
"f32_sub",
9496
"f32_mul",
@@ -111,6 +113,7 @@
111113
"f64_to_f32",
112114
"f64_to_f128",
113115
"f64_round_to_int",
116+
"f64_neg",
114117
"f64_add",
115118
"f64_sub",
116119
"f64_mul",
@@ -133,6 +136,7 @@
133136
"f128_to_f32",
134137
"f128_to_f64",
135138
"f128_round_to_int",
139+
"f128_neg",
136140
"f128_add",
137141
"f128_sub",
138142
"f128_mul",
@@ -195,6 +199,7 @@
195199
f16_to_f64,
196200
f16_to_f128,
197201
f16_round_to_int,
202+
f16_neg,
198203
f16_add,
199204
f16_sub,
200205
f16_mul,
@@ -220,6 +225,7 @@
220225
f32_to_f64,
221226
f32_to_f128,
222227
f32_round_to_int,
228+
f32_neg,
223229
f32_add,
224230
f32_sub,
225231
f32_mul,
@@ -242,6 +248,7 @@
242248
f64_to_f32,
243249
f64_to_f128,
244250
f64_round_to_int,
251+
f64_neg,
245252
f64_add,
246253
f64_sub,
247254
f64_mul,
@@ -264,6 +271,7 @@
264271
f128_to_f32,
265272
f128_to_f64,
266273
f128_round_to_int,
274+
f128_neg,
267275
f128_add,
268276
f128_sub,
269277
f128_mul,

python/src/softfloatpy/_core.pyi

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,15 @@ class Float16:
12151215
"""
12161216
...
12171217

1218+
def neg(self) -> Self:
1219+
"""Negates the IEEE 754 binary16 floating point.
1220+
1221+
Returns:
1222+
The resulted number (``-x``).
1223+
1224+
"""
1225+
...
1226+
12181227
@classmethod
12191228
def add(cls, x: Self, y: Self) -> Self:
12201229
"""Adds the IEEE 754 binary16 floating points.
@@ -1717,6 +1726,15 @@ class Float32:
17171726
"""
17181727
...
17191728

1729+
def neg(self) -> Self:
1730+
"""Negates the IEEE 754 binary32 floating point.
1731+
1732+
Returns:
1733+
The resulted number (``-x``).
1734+
1735+
"""
1736+
...
1737+
17201738
@classmethod
17211739
def add(cls, x: Self, y: Self) -> Self:
17221740
"""Adds the IEEE 754 binary32 floating points.
@@ -2208,6 +2226,15 @@ class Float64:
22082226
"""
22092227
...
22102228

2229+
def neg(self) -> Self:
2230+
"""Negates the IEEE 754 binary64 floating point.
2231+
2232+
Returns:
2233+
The resulted number (``-x``).
2234+
2235+
"""
2236+
...
2237+
22112238
@classmethod
22122239
def add(cls, x: Self, y: Self) -> Self:
22132240
"""Adds the IEEE 754 binary64 floating points.
@@ -2711,6 +2738,15 @@ class Float128:
27112738
"""
27122739
...
27132740

2741+
def neg(self) -> Self:
2742+
"""Negates the IEEE 754 binary128 floating point.
2743+
2744+
Returns:
2745+
The resulted number (``-x``).
2746+
2747+
"""
2748+
...
2749+
27142750
@classmethod
27152751
def add(cls, x: Self, y: Self) -> Self:
27162752
"""Adds the IEEE 754 binary128 floating points.
@@ -3410,6 +3446,19 @@ def f16_round_to_int(
34103446
...
34113447

34123448

3449+
def f16_neg(x: Float16) -> Float16:
3450+
"""Negates the IEEE 754 binary16 floating point.
3451+
3452+
Args:
3453+
x: The floating point to be negated.
3454+
3455+
Returns:
3456+
The resulted number expressed as an IEEE 754 binary16 floating point (``-x``).
3457+
3458+
"""
3459+
...
3460+
3461+
34133462
def f16_add(x: Float16, y: Float16) -> Float16:
34143463
"""Adds the IEEE 754 binary16 floating points.
34153464
@@ -3779,6 +3828,19 @@ def f32_round_to_int(
37793828
...
37803829

37813830

3831+
def f32_neg(x: Float32) -> Float32:
3832+
"""Negates the IEEE 754 binary32 floating point.
3833+
3834+
Args:
3835+
x: The floating point to be negated.
3836+
3837+
Returns:
3838+
The resulted number expressed as an IEEE 754 binary32 floating point (``-x``).
3839+
3840+
"""
3841+
...
3842+
3843+
37823844
def f32_add(x: Float32, y: Float32) -> Float32:
37833845
"""Adds the IEEE 754 binary32 floating points.
37843846
@@ -4109,6 +4171,19 @@ def f64_round_to_int(
41094171
...
41104172

41114173

4174+
def f64_neg(x: Float64) -> Float64:
4175+
"""Negates the IEEE 754 binary64 floating point.
4176+
4177+
Args:
4178+
x: The floating point to be negated.
4179+
4180+
Returns:
4181+
The resulted number expressed as an IEEE 754 binary64 floating point (``-x``).
4182+
4183+
"""
4184+
...
4185+
4186+
41124187
def f64_add(x: Float64, y: Float64) -> Float64:
41134188
"""Adds the IEEE 754 binary64 floating points.
41144189
@@ -4439,6 +4514,19 @@ def f128_round_to_int(
44394514
...
44404515

44414516

4517+
def f128_neg(x: Float128) -> Float128:
4518+
"""Negates the IEEE 754 binary128 floating point.
4519+
4520+
Args:
4521+
x: The floating point to be negated.
4522+
4523+
Returns:
4524+
The resulted number expressed as an IEEE 754 binary128 floating point (``-x``).
4525+
4526+
"""
4527+
...
4528+
4529+
44424530
def f128_add(x: Float128, y: Float128) -> Float128:
44434531
"""Adds the IEEE 754 binary128 floating points.
44444532

0 commit comments

Comments
 (0)