maths/radix2_fft.py: Fix calculation for Python 3.14 (#12772)

* maths/radix2_fft.py: Fix calculation for Python 3.14

As suggested at:
* https://github.com/TheAlgorithms/Python/issues/12729#issuecomment-2878608477
* https://github.com/TheAlgorithms/Python/pull/12710#discussion_r2080117333

@MaximSmolskiy @KirilBangachev @skirpichev Careful review, please.  I am just implementing the suggestion, but I do not have any expertise in this area.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Change test results

* GitHub Actions: Rename job from build to directory_writer

It is confusing to have two jobs named `build`.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2025-05-29 08:56:25 +02:00
committed by GitHub
parent e26c388af0
commit d0d7f0b18a
2 changed files with 6 additions and 4 deletions

View File

@ -3,7 +3,7 @@
name: directory_writer name: directory_writer
on: [push] on: [push]
jobs: jobs:
build: directory_writer:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

View File

@ -40,13 +40,13 @@ class FFT:
Print product Print product
>>> x.product # 2x + 3x^2 + 8x^3 + 4x^4 + 6x^5 >>> x.product # 2x + 3x^2 + 8x^3 + 4x^4 + 6x^5
[(-0+0j), (2+0j), (3+0j), (8+0j), (6+0j), (8+0j)] [(-0-0j), (2+0j), (3-0j), (8-0j), (6+0j), (8+0j)]
__str__ test __str__ test
>>> print(x) >>> print(x)
A = 0*x^0 + 1*x^1 + 2*x^0 + 3*x^2 A = 0*x^0 + 1*x^1 + 2*x^0 + 3*x^2
B = 0*x^2 + 1*x^3 + 2*x^4 B = 0*x^2 + 1*x^3 + 2*x^4
A*B = 0*x^(-0+0j) + 1*x^(2+0j) + 2*x^(3+0j) + 3*x^(8+0j) + 4*x^(6+0j) + 5*x^(8+0j) A*B = 0*x^(-0-0j) + 1*x^(2+0j) + 2*x^(3-0j) + 3*x^(8-0j) + 4*x^(6+0j) + 5*x^(8+0j)
""" """
def __init__(self, poly_a=None, poly_b=None): def __init__(self, poly_a=None, poly_b=None):
@ -147,7 +147,9 @@ class FFT:
inverce_c = new_inverse_c inverce_c = new_inverse_c
next_ncol *= 2 next_ncol *= 2
# Unpack # Unpack
inverce_c = [round(x[0].real, 8) + round(x[0].imag, 8) * 1j for x in inverce_c] inverce_c = [
complex(round(x[0].real, 8), round(x[0].imag, 8)) for x in inverce_c
]
# Remove leading 0's # Remove leading 0's
while inverce_c[-1] == 0: while inverce_c[-1] == 0: