├── apfloat └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apfloat │ │ │ ├── doc-files │ │ │ └── apfloat-classes.gif │ │ │ ├── spi │ │ │ ├── doc-files │ │ │ │ └── spi-classes.gif │ │ │ ├── MatrixBuilder.java │ │ │ ├── ExecutionBuilder.java │ │ │ ├── AdditionBuilder.java │ │ │ ├── ConvolutionBuilder.java │ │ │ ├── CarryCRTBuilder.java │ │ │ ├── ExecutionStrategy.java │ │ │ ├── ConvolutionStrategy.java │ │ │ ├── Factor3NTTStepStrategy.java │ │ │ ├── CarryCRTStrategy.java │ │ │ ├── NTTBuilder.java │ │ │ ├── NTTConvolutionStepStrategy.java │ │ │ └── RadixConstants.java │ │ │ ├── internal │ │ │ ├── doc-files │ │ │ │ ├── new-sequence.gif │ │ │ │ ├── multiply-sequence.gif │ │ │ │ ├── biginteger-comparison.gif │ │ │ │ └── implementation-classes.gif │ │ │ ├── Parallelizable.java │ │ │ ├── ParallelExecutionStrategy.java │ │ │ ├── IntConstants.java │ │ │ ├── LongConstants.java │ │ │ ├── DoubleConstants.java │ │ │ ├── FloatConstants.java │ │ │ ├── ParallelExecutionBuilder.java │ │ │ ├── NTTStrategyDecorator.java │ │ │ ├── DecorableNTTStrategy.java │ │ │ ├── IntModConstants.java │ │ │ ├── FloatModConstants.java │ │ │ ├── LongModConstants.java │ │ │ └── DoubleModConstants.java │ │ │ ├── ShutdownMap.java │ │ │ ├── ConcurrentSoftHashMap.java │ │ │ ├── ApfloatLocalizedException.java │ │ │ └── RootFinder.java │ ├── resources │ │ ├── META-INF │ │ │ └── services │ │ │ │ └── org.apfloat.spi.BuilderFactory │ │ └── apfloat.properties │ └── template │ │ └── org │ │ └── apfloat │ │ └── internal │ │ ├── RawtypeMatrixBuilder.java │ │ ├── RawtypeAdditionBuilder.java │ │ ├── RawtypeCarryCRTBuilder.java │ │ ├── RawtypeScramble.java │ │ ├── RawtypeNTTBuilder.java │ │ ├── RawtypeMemoryArrayAccess.java │ │ ├── RawtypeDataStorageBuilder.java │ │ ├── RawtypeApfloatBuilder.java │ │ ├── RawtypeAdditionStrategy.java │ │ └── RawtypeConvolutionBuilder.java │ └── test │ ├── template │ └── org │ │ └── apfloat │ │ └── internal │ │ ├── RawtypeTestCase.java │ │ ├── RawtypeMemoryDataStorageTest.java │ │ ├── RawtypeScrambleTest.java │ │ ├── RawtypeConvolutionStrategyTestCase.java │ │ ├── RawtypeWTablesTest.java │ │ └── RawtypeMediumConvolutionStrategyTest.java │ └── java │ └── org │ └── apfloat │ ├── ApfloatTestCase.java │ ├── spi │ └── FilenameGeneratorTest.java │ ├── ShutdownMapTest.java │ ├── ApfloatRuntimeExceptionTest.java │ └── GCDHelperTest.java ├── apfloat-aparapi ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── org.apfloat.spi.BuilderFactory │ │ └── java │ │ │ └── org │ │ │ └── apfloat │ │ │ └── aparapi │ │ │ ├── IntAparapiColumnTwoPassFNTStrategy.java │ │ │ ├── LongAparapiColumnTwoPassFNTStrategy.java │ │ │ ├── IntAparapiColumnSixStepFNTStrategy.java │ │ │ ├── IntAparapiTwoPassFNTStrategy.java │ │ │ ├── LongAparapiColumnSixStepFNTStrategy.java │ │ │ ├── LongAparapiTwoPassFNTStrategy.java │ │ │ ├── IntAparapiSixStepFNTStrategy.java │ │ │ ├── LongAparapiSixStepFNTStrategy.java │ │ │ ├── package-info.java │ │ │ ├── IntAparapiBuilderFactory.java │ │ │ ├── IntAparapiFactor3NTTStrategy.java │ │ │ ├── LongAparapiFactor3NTTStrategy.java │ │ │ ├── LongAparapiBuilderFactory.java │ │ │ └── RangeHelper.java │ └── test │ │ └── java │ │ └── org │ │ └── apfloat │ │ └── aparapi │ │ ├── IntAparapiTwoPassFNTStrategyTest.java │ │ ├── LongAparapiTwoPassFNTStrategyTest.java │ │ ├── IntAparapiColumnTwoPassFNTStrategyTest.java │ │ ├── LongAparapiColumnTwoPassFNTStrategyTest.java │ │ └── IntAparapiColumnSixStepFNTStrategyTest.java └── pom.xml ├── .gitignore ├── apfloat-samples └── src │ └── main │ ├── resources │ └── cluster.properties │ └── java │ └── org │ └── apfloat │ └── samples │ ├── Operation.java │ ├── PiParallelApplet.java │ ├── PiParallelGUI.java │ ├── OperationExecutor.java │ ├── ApfloatHolder.java │ └── LocalOperationExecutor.java ├── readme.html ├── src ├── site │ └── resources │ │ ├── applet.html │ │ └── applet │ │ ├── piparallel.html │ │ ├── signedpiparallel.html │ │ ├── pi.html │ │ ├── signedpi.html │ │ ├── calculator.html │ │ └── signedcalculator.html └── main │ └── javadoc │ └── overview.html ├── LICENSE.txt ├── README.md ├── .github └── workflows │ └── maven.yml ├── apfloat-calc └── src │ └── main │ └── java │ └── org │ └── apfloat │ └── calc │ ├── package-info.java │ ├── CalculatorGUI.java │ └── Calculator.java ├── apfloat-jscience ├── src │ └── main │ │ └── java │ │ └── org │ │ └── apfloat │ │ └── jscience │ │ └── package-info.java └── pom.xml └── apfloat-applet └── pom.xml /apfloat/src/main/java/org/apfloat/doc-files/apfloat-classes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtommila/apfloat/HEAD/apfloat/src/main/java/org/apfloat/doc-files/apfloat-classes.gif -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/doc-files/spi-classes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtommila/apfloat/HEAD/apfloat/src/main/java/org/apfloat/spi/doc-files/spi-classes.gif -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/resources/META-INF/services/org.apfloat.spi.BuilderFactory: -------------------------------------------------------------------------------- 1 | org.apfloat.aparapi.IntAparapiBuilderFactory 2 | org.apfloat.aparapi.LongAparapiBuilderFactory 3 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/doc-files/new-sequence.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtommila/apfloat/HEAD/apfloat/src/main/java/org/apfloat/internal/doc-files/new-sequence.gif -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/doc-files/multiply-sequence.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtommila/apfloat/HEAD/apfloat/src/main/java/org/apfloat/internal/doc-files/multiply-sequence.gif -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/doc-files/biginteger-comparison.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtommila/apfloat/HEAD/apfloat/src/main/java/org/apfloat/internal/doc-files/biginteger-comparison.gif -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/doc-files/implementation-classes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtommila/apfloat/HEAD/apfloat/src/main/java/org/apfloat/internal/doc-files/implementation-classes.gif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse 2 | .classpath 3 | .metadata/ 4 | .project 5 | .settings/ 6 | 7 | # Intellij 8 | .idea/ 9 | *.iml 10 | *.iws 11 | 12 | # Mac 13 | .DS_Store 14 | 15 | # Maven 16 | log/ 17 | target/ 18 | -------------------------------------------------------------------------------- /apfloat/src/main/resources/META-INF/services/org.apfloat.spi.BuilderFactory: -------------------------------------------------------------------------------- 1 | org.apfloat.internal.IntBuilderFactory 2 | org.apfloat.internal.LongBuilderFactory 3 | org.apfloat.internal.FloatBuilderFactory 4 | org.apfloat.internal.DoubleBuilderFactory 5 | -------------------------------------------------------------------------------- /apfloat-samples/src/main/resources/cluster.properties: -------------------------------------------------------------------------------- 1 | # The format of the file is 2 | # 3 | # server1=hostname:port 4 | # server2=hostname2:port 5 | # server3=hostname3:port 6 | # 7 | # Optionally, relative weights can be specified for the server nodes, e.g. 8 | # 9 | # weight1=100 10 | # weight2=150 11 | # weight3=200 12 | 13 | -------------------------------------------------------------------------------- /readme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Apfloat Readme 8 | 9 | 10 | 11 | 12 | 13 | 14 |

Apfloat

15 | 16 | Copyright © 2025 Mikko Tommila

17 | 18 | This work is licensed under the terms of the MIT license. 19 | See the MIT License for more details.

20 | 21 | If you have any questions or need a different type of license, please 22 | contact the author.

23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/site/resources/applet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Sample Apfloat Applets 7 | 8 | 9 | 10 | 11 |

Sample Apfloat Applets

12 | 13 | Arbitrary precision calculator applet
14 | Unsigned 15 | Signed

16 | 17 | Pi calculation applet
18 | Single-thread Unsigned 19 | Signed
20 | Multi-thread Unsigned 21 | Signed

22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/site/resources/applet/piparallel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Parallel Pi Calculator Applet 6 | 7 | 8 | 9 |

Parallel Pi Calculator Applet

10 | 11 | You can calculate pi to millions of digits of precision with this applet. 12 | It can use multiple CPUs to perform calculations in parallel. 13 | 14 |
15 | 16 | 18 | Your browser is completely ignoring the <applet> tag. 19 | 20 | 21 |
22 | 23 | Back to sample apfloat applets.

24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/site/resources/applet/signedpiparallel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Signed Parallel Pi Calculator Applet 6 | 7 | 8 | 9 |

Signed Parallel Pi Calculator Applet

10 | 11 | You can calculate pi to millions of digits of precision with this applet. 12 | It can use multiple CPUs to perform calculations in parallel. 13 | 14 |
15 | 16 | 18 | Your browser is completely ignoring the <applet> tag. 19 | 20 | 21 |
22 | 23 | Back to sample apfloat applets.

24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/site/resources/applet/pi.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Pi Calculator Applet 6 | 7 | 8 | 9 | 10 |

Pi Calculator Applet

11 | 12 | You can calculate pi to millions of digits of precision with this applet. 13 | It supports four algorithms for calculating pi, and any radix between 2 and 36. 14 | 15 |
16 | 17 | 19 | Your browser is completely ignoring the <applet> tag. 20 | 21 | 22 |
23 | 24 | Back to sample apfloat applets.

25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/site/resources/applet/signedpi.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Signed Pi Calculator Applet 6 | 7 | 8 | 9 | 10 |

Signed Pi Calculator Applet

11 | 12 | You can calculate pi to millions of digits of precision with this applet. 13 | It supports four algorithms for calculating pi, and any radix between 2 and 36. 14 | 15 |
16 | 17 | 19 | Your browser is completely ignoring the <applet> tag. 20 | 21 | 22 |
23 | 24 | Back to sample apfloat applets.

25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/javadoc/overview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Apfloat is an arbitrary precision arithmetic library. Most operations e.g. 5 | multiplication can be done with O(n log n) complexity. That is, when 6 | the number of digits doubles, the execution time only slightly more than 7 | doubles.

8 | 9 | Apfloat requires Java 8 or later.

10 | 11 | The apfloat library has been designed for high performance, but as it is 100% 12 | Java, the achievement is somewhat limited compared to various other existing 13 | libraries written in C and assembler. For best performance it's recommended to 14 | use the fastest Java Virtual Machine available, for example OpenJDK's server VM.

15 | 16 | Apfloat is distributed under the terms of the 17 | MIT License 18 | and comes with NO WARRANTIES.

19 | 20 | To report bugs and submit questions or comments, please contact the author 21 | Mikko Tommila.

22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/site/resources/applet/calculator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Calculator Applet 6 | 7 | 8 | 9 | 10 |

Calculator Applet

11 | 12 | This is an arbitrary precision calculator applet. 13 | It works like any normal calculator, and allows calculating results to millions of digits of precision. 14 | In addition, it supports various special mathematical functions.

15 | 16 | Calculator help 17 | 18 |


19 | 20 | 22 | Your browser is completely ignoring the <applet> tag. 23 | 24 | 25 |
26 | 27 | Back to sample apfloat applets.

28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/site/resources/applet/signedcalculator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Signed Calculator Applet 6 | 7 | 8 | 9 | 10 |

Signed Calculator Applet

11 | 12 | This is an arbitrary precision calculator applet. 13 | It works like any normal calculator, and allows calculating results to millions of digits of precision. 14 | In addition, it supports various special mathematical functions.

15 | 16 | Calculator help 17 | 18 |


19 | 20 | 22 | Your browser is completely ignoring the <applet> tag. 23 | 24 | 25 |
26 | 27 | Back to sample apfloat applets.

28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Mikko Tommila 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apfloat 2 | 3 | Copyright © 2025 Mikko Tommila 4 | 5 | This work is licensed under the terms of the MIT license. See the [MIT License](LICENSE.txt) for more details. 6 | 7 | If you have any questions or need a different type of license, please [contact the author](mailto:Mikko.Tommila@apfloat.org). 8 | 9 | ## Building the Library 10 | 11 | To build the library quickly, without running unit tests (takes about 20 minutes) and without signing with GPG run: 12 | 13 | `mvn clean install -Dgpg.skip -Djarsigner.skip -DskipTests` 14 | 15 | To build the signed applet files, you need to first generate a signing key, e.g. with: 16 | 17 | `keytool -genkeypair -validity 21915 -dname "cn=Your Name, o=example.com" -storepass password -keypass password -alias mykey` 18 | 19 | and then build without -Djarsigner.skip. 20 | 21 | ## Running the Sample Applications 22 | 23 | To run the arbitrary precision calculator, run: 24 | 25 | `mvn -pl :apfloat-calc exec:java -Dexec.mainClass=org.apfloat.calc.CalculatorGUI` 26 | 27 | To run the pi calculator, run: 28 | 29 | `mvn -pl :apfloat-samples exec:java -Dexec.mainClass=org.apfloat.samples.PiParallelGUI` 30 | 31 | ## Apfloat website 32 | 33 | Go to the [apfloat for Java website](https://www.apfloat.org/apfloat_java/). 34 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Java CI with Maven 10 | 11 | on: 12 | push: 13 | branches: [ "main" ] 14 | pull_request: 15 | branches: [ "main" ] 16 | 17 | permissions: 18 | contents: write 19 | security-events: write 20 | 21 | jobs: 22 | build: 23 | 24 | runs-on: ubuntu-latest 25 | 26 | steps: 27 | - uses: actions/checkout@v4 28 | - name: Set up JDK 21 29 | uses: actions/setup-java@v4 30 | with: 31 | java-version: '21' 32 | distribution: 'corretto' 33 | check-latest: true 34 | cache: maven 35 | - name: Build with Maven 36 | run: mvn -B clean package -Dgpg.skip -Djarsigner.skip 37 | 38 | # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive 39 | - name: Update dependency graph 40 | uses: advanced-security/maven-dependency-submission-action@v4 41 | -------------------------------------------------------------------------------- /apfloat-calc/src/main/java/org/apfloat/calc/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | Arbitrary precision calculator interactive application. 27 | */ 28 | 29 | package org.apfloat.calc; 30 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/Parallelizable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Any task that can use a {@link ParallelRunner} to execute operations in parallel. 28 | * 29 | * @since 1.7.0 30 | * @version 1.8.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public interface Parallelizable 35 | { 36 | } 37 | -------------------------------------------------------------------------------- /apfloat-jscience/src/main/java/org/apfloat/jscience/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | JScience wrapper for apfloat.

27 | 28 | This package contains classes that allow using the apfloat library 29 | classes with the JScience library. For example, it's possible 30 | to perform arbitrary-precision matrix or polynomial operations. 31 | */ 32 | 33 | package org.apfloat.jscience; 34 | -------------------------------------------------------------------------------- /apfloat-samples/src/main/java/org/apfloat/samples/Operation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.samples; 25 | 26 | import java.io.Serializable; 27 | 28 | /** 29 | * Interface for implementing arbitrary operations to be executed. 30 | * 31 | * @version 1.9.0 32 | * @author Mikko Tommila 33 | */ 34 | 35 | @FunctionalInterface 36 | public interface Operation 37 | extends Serializable 38 | { 39 | /** 40 | * Executes some code, returning a value. 41 | * 42 | * @return Return value of the operation. 43 | */ 44 | 45 | public T execute(); 46 | } 47 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/ParallelExecutionStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import java.util.concurrent.Future; 27 | 28 | import org.apfloat.spi.ExecutionStrategy; 29 | 30 | /** 31 | * Execution strategy using the {@link ParallelRunner}. 32 | * 33 | * @since 1.9.0 34 | * @version 1.9.0 35 | * @author Mikko Tommila 36 | */ 37 | 38 | public class ParallelExecutionStrategy 39 | implements ExecutionStrategy 40 | { 41 | @Override 42 | public void wait(Future future) 43 | { 44 | ParallelRunner.wait(future); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/MatrixBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | /** 27 | * Interface of a factory for creating matrix related objects. 28 | * The factory method pattern is used. 29 | * 30 | * @see MatrixStrategy 31 | * 32 | * @since 1.7.0 33 | * @version 1.7.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public interface MatrixBuilder 38 | { 39 | /** 40 | * Creates an object for matrix operations. 41 | * 42 | * @return A suitable object for performing the matrix operations. 43 | */ 44 | 45 | public MatrixStrategy createMatrix(); 46 | } 47 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/IntConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various algorithms for the int type. 28 | * 29 | * @since 1.4 30 | * @version 1.4 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public interface IntConstants 35 | { 36 | /** 37 | * Relative cost of Karatsuba multiplication. 38 | */ 39 | 40 | public static final float KARATSUBA_COST_FACTOR = 4.8f; 41 | 42 | /** 43 | * Relative cost of NTT multiplication. 44 | */ 45 | 46 | public static final float NTT_COST_FACTOR = 4.1f; 47 | } 48 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/LongConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various algorithms for the long type. 28 | * 29 | * @since 1.4 30 | * @version 1.4 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public interface LongConstants 35 | { 36 | /** 37 | * Relative cost of Karatsuba multiplication. 38 | */ 39 | 40 | public static final float KARATSUBA_COST_FACTOR = 4.3f; 41 | 42 | /** 43 | * Relative cost of NTT multiplication. 44 | */ 45 | 46 | public static final float NTT_COST_FACTOR = 8.3f; 47 | } 48 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/DoubleConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various algorithms for the double type. 28 | * 29 | * @since 1.4 30 | * @version 1.4 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public interface DoubleConstants 35 | { 36 | /** 37 | * Relative cost of Karatsuba multiplication. 38 | */ 39 | 40 | public static final float KARATSUBA_COST_FACTOR = 4.3f; 41 | 42 | /** 43 | * Relative cost of NTT multiplication. 44 | */ 45 | 46 | public static final float NTT_COST_FACTOR = 6.2f; 47 | } 48 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/FloatConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various algorithms for the float type. 28 | * 29 | * @since 1.4 30 | * @version 1.4 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public interface FloatConstants 35 | { 36 | /** 37 | * Relative cost of Karatsuba multiplication. 38 | */ 39 | 40 | public static final float KARATSUBA_COST_FACTOR = 6.1f; 41 | 42 | /** 43 | * Relative cost of NTT multiplication. 44 | */ 45 | 46 | public static final float NTT_COST_FACTOR = 7.4f; 47 | } 48 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/ExecutionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | /** 27 | * Interface of a factory for creating execution related objects. 28 | * The factory method pattern is used. 29 | * 30 | * @see ExecutionStrategy 31 | * 32 | * @since 1.9.0 33 | * @version 1.9.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public interface ExecutionBuilder 38 | { 39 | /** 40 | * Creates an object for execution operations. 41 | * 42 | * @return A suitable object for performing the execution operations. 43 | */ 44 | 45 | public ExecutionStrategy createExecution(); 46 | } 47 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/IntAparapiColumnTwoPassFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | /** 27 | * Two-pass NTT implementation for the int element type using column orientation.

28 | * 29 | * @since 1.15.0 30 | * @version 1.15.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class IntAparapiColumnTwoPassFNTStrategy 35 | extends ColumnTwoPassFNTStrategy 36 | implements IntAparapiNTTStrategy 37 | { 38 | /** 39 | * Default constructor. 40 | */ 41 | 42 | public IntAparapiColumnTwoPassFNTStrategy() 43 | { 44 | super(new IntAparapiNTTStepStrategy(false)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/LongAparapiColumnTwoPassFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | /** 27 | * Two-pass NTT implementation for the long element type using column orientation.

28 | * 29 | * @since 1.15.0 30 | * @version 1.15.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class LongAparapiColumnTwoPassFNTStrategy 35 | extends ColumnTwoPassFNTStrategy 36 | implements LongAparapiNTTStrategy 37 | { 38 | /** 39 | * Default constructor. 40 | */ 41 | 42 | public LongAparapiColumnTwoPassFNTStrategy() 43 | { 44 | super(new LongAparapiNTTStepStrategy(false)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /apfloat-samples/src/main/java/org/apfloat/samples/PiParallelApplet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.samples; 25 | 26 | import java.awt.Container; 27 | 28 | /** 29 | * Applet for calculating pi using multiple threads in parallel. 30 | * 31 | * @version 1.9.0 32 | * @author Mikko Tommila 33 | */ 34 | 35 | public class PiParallelApplet 36 | extends PiApplet 37 | { 38 | /** 39 | * Default constructor. 40 | */ 41 | 42 | public PiParallelApplet() 43 | { 44 | } 45 | 46 | @Override 47 | protected Container getContents() 48 | { 49 | return new PiParallelAWT(this); 50 | } 51 | 52 | private static final long serialVersionUID = 1L; 53 | } 54 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/IntAparapiColumnSixStepFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | /** 27 | * Six-step NTT implementation for the int element type using column orientation.

28 | * 29 | * @since 1.15.0 30 | * @version 1.15.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class IntAparapiColumnSixStepFNTStrategy 35 | extends ColumnSixStepFNTStrategy 36 | implements IntAparapiNTTStrategy 37 | { 38 | /** 39 | * Default constructor. 40 | */ 41 | 42 | public IntAparapiColumnSixStepFNTStrategy() 43 | { 44 | super(new IntAparapiNTTStepStrategy(false), new IntAparapiMatrixStrategy()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/IntAparapiTwoPassFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.internal.TwoPassFNTStrategy; 27 | 28 | /** 29 | * Two-pass NTT implementation for the int element type using row orientation.

30 | * 31 | * @since 1.15.0 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class IntAparapiTwoPassFNTStrategy 37 | extends TwoPassFNTStrategy 38 | implements IntAparapiNTTStrategy 39 | { 40 | /** 41 | * Default constructor. 42 | */ 43 | 44 | public IntAparapiTwoPassFNTStrategy() 45 | { 46 | super(new IntAparapiNTTStepStrategy(true)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/LongAparapiColumnSixStepFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | /** 27 | * Six-step NTT implementation for the long element type using column orientation.

28 | * 29 | * @since 1.15.0 30 | * @version 1.15.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class LongAparapiColumnSixStepFNTStrategy 35 | extends ColumnSixStepFNTStrategy 36 | implements LongAparapiNTTStrategy 37 | { 38 | /** 39 | * Default constructor. 40 | */ 41 | 42 | public LongAparapiColumnSixStepFNTStrategy() 43 | { 44 | super(new LongAparapiNTTStepStrategy(false), new LongAparapiMatrixStrategy()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/LongAparapiTwoPassFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.internal.TwoPassFNTStrategy; 27 | 28 | /** 29 | * Two-pass NTT implementation for the long element type using row orientation.

30 | * 31 | * @since 1.15.0 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class LongAparapiTwoPassFNTStrategy 37 | extends TwoPassFNTStrategy 38 | implements LongAparapiNTTStrategy 39 | { 40 | /** 41 | * Default constructor. 42 | */ 43 | 44 | public LongAparapiTwoPassFNTStrategy() 45 | { 46 | super(new LongAparapiNTTStepStrategy(true)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/ParallelExecutionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.ExecutionBuilder; 27 | import org.apfloat.spi.ExecutionStrategy; 28 | 29 | /** 30 | * Returns an execution strategy using the {@link ParallelRunner}. 31 | * 32 | * @since 1.9.0 33 | * @version 1.9.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class ParallelExecutionBuilder 38 | implements ExecutionBuilder 39 | { 40 | @Override 41 | public ExecutionStrategy createExecution() 42 | { 43 | return ParallelExecutionBuilder.executionStrategy; 44 | } 45 | 46 | private static ExecutionStrategy executionStrategy = new ParallelExecutionStrategy(); 47 | } 48 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/IntAparapiSixStepFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.internal.SixStepFNTStrategy; 27 | 28 | /** 29 | * Six-step NTT implementation for the int element type using row orientation.

30 | * 31 | * @since 1.8.3 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class IntAparapiSixStepFNTStrategy 37 | extends SixStepFNTStrategy 38 | implements IntAparapiNTTStrategy 39 | { 40 | /** 41 | * Default constructor. 42 | */ 43 | 44 | public IntAparapiSixStepFNTStrategy() 45 | { 46 | super(new IntAparapiNTTStepStrategy(true), new IntAparapiMatrixStrategy()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/LongAparapiSixStepFNTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.internal.SixStepFNTStrategy; 27 | 28 | /** 29 | * Six-step NTT implementation for the long element type using row orientation.

30 | * 31 | * @since 1.8.3 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class LongAparapiSixStepFNTStrategy 37 | extends SixStepFNTStrategy 38 | implements LongAparapiNTTStrategy 39 | { 40 | /** 41 | * Default constructor. 42 | */ 43 | 44 | public LongAparapiSixStepFNTStrategy() 45 | { 46 | super(new LongAparapiNTTStepStrategy(true), new LongAparapiMatrixStrategy()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | Transforms for using a GPU via the aparapi library.

27 | 28 | This package contains Number-Theoretic Transform implementations that can use 29 | the GPU (Graphics Processing Unit) for executing the transforms. There is significant 30 | overhead in invoking the GPU, e.g. in transferring the data between the main memory 31 | and the GPU memory, so for small data sets there is usually no performance improvement, 32 | and in many cases performance can be even significantly slower. However for very large 33 | calculations, e.g. one billion digits, using the GPU can improve the performance noticeably, 34 | depending on the hardware used. 35 | */ 36 | 37 | package org.apfloat.aparapi; 38 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/AdditionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | /** 27 | * Interface of a factory for creating addition strategies. 28 | * The factory method pattern is used. 29 | * 30 | * @param The element type of the addition strategies. 31 | * 32 | * @see AdditionStrategy 33 | * 34 | * @since 1.7.0 35 | * @version 1.7.0 36 | * @author Mikko Tommila 37 | */ 38 | 39 | public interface AdditionBuilder 40 | { 41 | /** 42 | * Returns an addition strategy of suitable type for the specified radix. 43 | * 44 | * @param radix The radix that will be used. 45 | * 46 | * @return A suitable object for performing the addition. 47 | */ 48 | 49 | public AdditionStrategy createAddition(int radix); 50 | } 51 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/NTTStrategyDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.ArrayAccess; 27 | 28 | /** 29 | * Decorator to perform pre- and post-processing on an NTTStrategy. 30 | * 31 | * @since 1.15.0 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public interface NTTStrategyDecorator 37 | { 38 | /** 39 | * Prepare the data for the (inverse) transform. 40 | * 41 | * @param arrayAccess The data to prepare. 42 | */ 43 | 44 | public void beforeTransform(ArrayAccess arrayAccess); 45 | 46 | /** 47 | * Finish processing the data after the (inverse) transform. 48 | * 49 | * @param arrayAccess The data to finish. 50 | */ 51 | 52 | public void afterTransform(ArrayAccess arrayAccess); 53 | } 54 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeMatrixBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.MatrixBuilder; 27 | import org.apfloat.spi.MatrixStrategy; 28 | 29 | /** 30 | * Creates matrix operations objects, for the 31 | * rawtype type. 32 | * 33 | * @since 1.7.0 34 | * @version 1.7.0 35 | * @author Mikko Tommila 36 | */ 37 | 38 | public class RawtypeMatrixBuilder 39 | implements MatrixBuilder 40 | { 41 | /** 42 | * Default constructor. 43 | */ 44 | 45 | public RawtypeMatrixBuilder() 46 | { 47 | } 48 | 49 | @Override 50 | public MatrixStrategy createMatrix() 51 | { 52 | return RawtypeMatrixBuilder.matrixStrategy; 53 | } 54 | 55 | private static MatrixStrategy matrixStrategy = new RawtypeMatrixStrategy(); 56 | } 57 | -------------------------------------------------------------------------------- /apfloat/src/test/template/org/apfloat/internal/RawtypeTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import java.util.Properties; 27 | 28 | import org.apfloat.*; 29 | 30 | import junit.framework.TestCase; 31 | 32 | /** 33 | * @version 1.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class RawtypeTestCase 38 | extends TestCase 39 | { 40 | public RawtypeTestCase() 41 | { 42 | } 43 | 44 | public RawtypeTestCase(String methodName) 45 | { 46 | super(methodName); 47 | } 48 | 49 | @Override 50 | protected void setUp() 51 | { 52 | Properties properties = new Properties(); 53 | properties.setProperty(ApfloatContext.BUILDER_FACTORY, "org.apfloat.internal.RawtypeBuilderFactory"); 54 | 55 | ApfloatContext.getContext().setProperties(properties); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeAdditionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.AdditionBuilder; 27 | import org.apfloat.spi.AdditionStrategy; 28 | 29 | /** 30 | * Creates additions for the specified radix and the rawtype element type.

31 | * 32 | * @since 1.7.0 33 | * @version 1.7.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class RawtypeAdditionBuilder 38 | implements AdditionBuilder 39 | { 40 | /** 41 | * Default constructor. 42 | */ 43 | 44 | public RawtypeAdditionBuilder() 45 | { 46 | } 47 | 48 | @Override 49 | public AdditionStrategy createAddition(int radix) 50 | { 51 | AdditionStrategy additionStrategy = new RawtypeAdditionStrategy(radix); 52 | return additionStrategy; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/ConvolutionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | /** 27 | * Interface of a factory for creating convolutors. 28 | * The factory method pattern is used. 29 | * 30 | * @see ConvolutionStrategy 31 | * 32 | * @version 1.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public interface ConvolutionBuilder 37 | { 38 | /** 39 | * Returns a convolution strategy of suitable 40 | * type for the specified length. 41 | * 42 | * @param radix The radix that will be used. 43 | * @param size1 Length of first data set. 44 | * @param size2 Length of second data set. 45 | * @param resultSize Minimum number of elements needed in the result data. 46 | * 47 | * @return A suitable object for performing the convolution. 48 | */ 49 | 50 | public ConvolutionStrategy createConvolution(int radix, long size1, long size2, long resultSize); 51 | } 52 | -------------------------------------------------------------------------------- /apfloat-samples/src/main/java/org/apfloat/samples/PiParallelGUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.samples; 25 | 26 | import java.awt.Container; 27 | 28 | /** 29 | * AWT client application for calculating pi using multiple threads in parallel. 30 | * 31 | * @version 1.9.0 32 | * @author Mikko Tommila 33 | */ 34 | 35 | public class PiParallelGUI 36 | extends PiGUI 37 | { 38 | /** 39 | * Default constructor. 40 | */ 41 | 42 | protected PiParallelGUI() 43 | { 44 | } 45 | 46 | @Override 47 | protected Container getContents() 48 | { 49 | return new PiParallelAWT(this); 50 | } 51 | 52 | /** 53 | * Command-line entry point. 54 | * 55 | * @param args Command-line parameters. 56 | */ 57 | 58 | public static void main(String[] args) 59 | { 60 | new PiParallelGUI(); 61 | } 62 | 63 | private static final long serialVersionUID = 1L; 64 | } 65 | -------------------------------------------------------------------------------- /apfloat/src/test/java/org/apfloat/ApfloatTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import junit.framework.TestCase; 27 | 28 | /** 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public class ApfloatTestCase 34 | extends TestCase 35 | { 36 | public ApfloatTestCase(String methodName) 37 | { 38 | super(methodName); 39 | } 40 | 41 | public static void assertEquals(String message, Apcomplex a, Apcomplex b, Apfloat delta) 42 | { 43 | if (ApcomplexMath.abs(a.subtract(b)).compareTo(delta) > 0) 44 | { 45 | assertEquals(message, a.toString(), b.toString()); 46 | } 47 | } 48 | 49 | public static void assertEquals(String message, Apfloat a, Apfloat b, Apfloat delta) 50 | { 51 | if (ApfloatMath.abs(a.subtract(b)).compareTo(delta) > 0) 52 | { 53 | assertEquals(message, a.toString(), b.toString()); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /apfloat-applet/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.apfloat 7 | apfloat-parent 8 | 1.15.1-SNAPSHOT 9 | 10 | 11 | apfloat-applet 12 | 13 | apfloat-applet 14 | Configuration for apfloat to not use disk files for data storage 15 | https://www.apfloat.org 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.apfloat 23 | apfloat 24 | 25 | 26 | junit 27 | junit 28 | test 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.apache.maven.plugins 36 | maven-javadoc-plugin 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-shade-plugin 45 | 46 | 47 | 48 | shade 49 | 50 | 51 | 52 | 53 | org.apfloat:apfloat-applet 54 | 55 | 56 | ${project.build.directory}/applet.jar 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/ShutdownMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2024 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import java.util.Map; 27 | import java.util.AbstractMap; 28 | import java.util.Set; 29 | 30 | /** 31 | * Map that always throws ApfloatRuntimeException on all operations. 32 | * Can be used to replace cache maps after JVM shutdown and clean-up 33 | * has been initiated to prevent other threads from performing any operations. 34 | * 35 | * @since 1.6.2 36 | * @version 1.15.0 37 | * @author Mikko Tommila 38 | */ 39 | 40 | class ShutdownMap 41 | extends AbstractMap 42 | { 43 | public ShutdownMap() 44 | { 45 | } 46 | 47 | @Override 48 | public Set> entrySet() 49 | { 50 | throw new ApfloatRuntimeException("Shutdown in progress", "shutdown"); 51 | } 52 | 53 | @Override 54 | public V put(K key, V value) 55 | { 56 | throw new ApfloatRuntimeException("Shutdown in progress", "shutdown"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeCarryCRTBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.CarryCRTBuilder; 27 | import org.apfloat.spi.CarryCRTStrategy; 28 | import org.apfloat.spi.CarryCRTStepStrategy; 29 | 30 | /** 31 | * Creates carry-CRT related objects, for the 32 | * rawtype type. 33 | * 34 | * @since 1.7.0 35 | * @version 1.7.0 36 | * @author Mikko Tommila 37 | */ 38 | 39 | public class RawtypeCarryCRTBuilder 40 | implements CarryCRTBuilder 41 | { 42 | /** 43 | * Default constructor. 44 | */ 45 | 46 | public RawtypeCarryCRTBuilder() 47 | { 48 | } 49 | 50 | @Override 51 | public CarryCRTStrategy createCarryCRT(int radix) 52 | { 53 | return new StepCarryCRTStrategy(radix); 54 | } 55 | 56 | @Override 57 | public CarryCRTStepStrategy createCarryCRTSteps(int radix) 58 | { 59 | return new RawtypeCarryCRTStepStrategy(radix); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/IntAparapiBuilderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.ApfloatContext; 27 | import org.apfloat.spi.NTTBuilder; 28 | import org.apfloat.internal.IntBuilderFactory; 29 | 30 | /** 31 | * Builder factory for aparapi transform implementations for the int element type. 32 | * 33 | * @since 1.8.3 34 | * @version 1.15.0 35 | * @author Mikko Tommila 36 | */ 37 | 38 | public class IntAparapiBuilderFactory 39 | extends IntBuilderFactory 40 | { 41 | /** 42 | * Default constructor. 43 | */ 44 | 45 | public IntAparapiBuilderFactory() 46 | { 47 | boolean rowOrientation = Boolean.parseBoolean(ApfloatContext.getContext().getProperty("rowOrientation")); 48 | this.nttBuilder = new IntAparapiNTTBuilder(rowOrientation); 49 | } 50 | 51 | @Override 52 | public NTTBuilder getNTTBuilder() 53 | { 54 | return this.nttBuilder; 55 | } 56 | 57 | private NTTBuilder nttBuilder; 58 | } 59 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/IntAparapiFactor3NTTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.spi.NTTStrategy; 27 | 28 | /** 29 | * Factor-3 NTT implementation for the int element type.

30 | * 31 | * @since 1.8.3 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class IntAparapiFactor3NTTStrategy 37 | extends DecorableFactor3NTTStrategy 38 | implements IntAparapiNTTStrategy 39 | { 40 | /** 41 | * Creates a new factor-3 transform strategy on top of an existing transform. 42 | * The underlying transform needs to be capable of only doing transforms of 43 | * length 2n. 44 | * 45 | * @param factor2Strategy The underlying transformation strategy, that can be capable of only doing radix-2 transforms. 46 | */ 47 | 48 | public IntAparapiFactor3NTTStrategy(NTTStrategy factor2Strategy) 49 | { 50 | super(factor2Strategy, new IntAparapiFactor3NTTStepStrategy()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/LongAparapiFactor3NTTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.spi.NTTStrategy; 27 | 28 | /** 29 | * Factor-3 NTT implementation for the long element type.

30 | * 31 | * @since 1.8.3 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class LongAparapiFactor3NTTStrategy 37 | extends DecorableFactor3NTTStrategy 38 | implements LongAparapiNTTStrategy 39 | { 40 | /** 41 | * Creates a new factor-3 transform strategy on top of an existing transform. 42 | * The underlying transform needs to be capable of only doing transforms of 43 | * length 2n. 44 | * 45 | * @param factor2Strategy The underlying transformation strategy, that can be capable of only doing radix-2 transforms. 46 | */ 47 | 48 | public LongAparapiFactor3NTTStrategy(NTTStrategy factor2Strategy) 49 | { 50 | super(factor2Strategy, new LongAparapiFactor3NTTStepStrategy()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/LongAparapiBuilderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.ApfloatContext; 27 | import org.apfloat.spi.NTTBuilder; 28 | import org.apfloat.internal.LongBuilderFactory; 29 | 30 | /** 31 | * Builder factory for aparapi transform implementations for the long element type. 32 | * 33 | * @since 1.8.3 34 | * @version 1.15.0 35 | * @author Mikko Tommila 36 | */ 37 | 38 | public class LongAparapiBuilderFactory 39 | extends LongBuilderFactory 40 | { 41 | /** 42 | * Default constructor. 43 | */ 44 | 45 | public LongAparapiBuilderFactory() 46 | { 47 | boolean rowOrientation = Boolean.parseBoolean(ApfloatContext.getContext().getProperty("rowOrientation")); 48 | this.nttBuilder = new LongAparapiNTTBuilder(rowOrientation); 49 | } 50 | 51 | @Override 52 | public NTTBuilder getNTTBuilder() 53 | { 54 | return this.nttBuilder; 55 | } 56 | 57 | private NTTBuilder nttBuilder; 58 | } 59 | -------------------------------------------------------------------------------- /apfloat/src/main/resources/apfloat.properties: -------------------------------------------------------------------------------- 1 | # The apfloat service provider class. 2 | # Out-of-the-box options are: 3 | # - org.apfloat.internal.IntBuilderFactory 4 | # - org.apfloat.internal.LongBuilderFactory 5 | # - org.apfloat.internal.FloatBuilderFactory 6 | # - org.apfloat.internal.DoubleBuilderFactory 7 | 8 | builderFactory=org.apfloat.internal.LongBuilderFactory 9 | 10 | # The default radix, used for newly created numbers unless otherwise specified. 11 | 12 | defaultRadix=10 13 | 14 | # Maximum memory block size (in bytes) that apfloat will try to allocate. 15 | # This should be somewhat less than what is available for the JVM 16 | # (the maximum heap size). 17 | 18 | maxMemoryBlockSize=50331648 19 | 20 | # Processor level 1 cache size in bytes. 21 | # Don't change it unless you know what you are doing. 22 | 23 | cacheL1Size=8192 24 | 25 | # Processor level 2 cache size in bytes. 26 | # Don't change it unless you know what you are doing. 27 | 28 | cacheL2Size=262144 29 | 30 | # Processor level 1 cache line size in bytes. 31 | # Don't change it unless you know what you are doing. 32 | 33 | cacheBurst=32 34 | 35 | # Threshold for storing numbers on disk. If the storage for the number 36 | # takes more than memoryThreshold bytes, it will by default be stored on 37 | # disk, otherwise in memory. 38 | 39 | memoryThreshold=65536 40 | 41 | # Threshold for using the shared memory. If the storage for the number 42 | # takes more than sharedMemoryTreshold bytes, the memory block usage 43 | # will be synchronized against the shared memory lock. 44 | 45 | sharedMemoryTreshold=1048576 46 | 47 | # Efficient disk I/O block size, in bytes. 48 | 49 | blockSize=65536 50 | 51 | # Number of physical processor cores in the computer. 52 | 53 | numberOfProcessors=1 54 | 55 | # Path for storing temporary files for disk-based numbers. 56 | 57 | filePath= 58 | 59 | # Initial value of the filenames for storing temporary files for disk-based 60 | # numbers. The filenames are generated as sequential numbers: 0, 1, 2, ... 61 | 62 | fileInitialValue=0 63 | 64 | # Filename suffix of the filenames for storing temporary files for disk-based 65 | # numbers. 66 | 67 | fileSuffix=.ap 68 | 69 | # Determines if clean-up of any remaining temporary files should be run 70 | # at program exit. This can't be enabled for unsigned applets. 71 | 72 | cleanupAtExit=true 73 | -------------------------------------------------------------------------------- /apfloat/src/test/java/org/apfloat/spi/FilenameGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | import junit.framework.TestCase; 27 | import junit.framework.TestSuite; 28 | 29 | /** 30 | * @version 1.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class FilenameGeneratorTest 35 | extends TestCase 36 | { 37 | public FilenameGeneratorTest(String methodName) 38 | { 39 | super(methodName); 40 | } 41 | 42 | public static void main(String[] args) 43 | { 44 | junit.textui.TestRunner.run(suite()); 45 | } 46 | 47 | public static TestSuite suite() 48 | { 49 | TestSuite suite = new TestSuite(); 50 | 51 | suite.addTest(new FilenameGeneratorTest("testGenerateFilename")); 52 | 53 | return suite; 54 | } 55 | 56 | public static void testGenerateFilename() 57 | { 58 | FilenameGenerator filenameGenerator = new FilenameGenerator("path", "5", "suffix"); 59 | assertEquals("filename", "path5suffix", filenameGenerator.generateFilename()); 60 | assertEquals("filename", "path6suffix", filenameGenerator.generateFilename()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/DecorableNTTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.ArrayAccess; 27 | 28 | /** 29 | * NTT strategy that can be decorated with a decorator. The decorator must be the object itself. 30 | * 31 | * @since 1.15.0 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public interface DecorableNTTStrategy 37 | { 38 | /** 39 | * Prepare the data for the (inverse) transform. 40 | * 41 | * @param arrayAccess The data to prepare. 42 | */ 43 | 44 | default public void preTransform(ArrayAccess arrayAccess) 45 | { 46 | if (this instanceof NTTStrategyDecorator) 47 | { 48 | ((NTTStrategyDecorator) this).beforeTransform(arrayAccess); 49 | } 50 | } 51 | 52 | /** 53 | * Finish processing the data after the (inverse) transform. 54 | * 55 | * @param arrayAccess The data to finish. 56 | */ 57 | 58 | default public void postTransform(ArrayAccess arrayAccess) 59 | { 60 | if (this instanceof NTTStrategyDecorator) 61 | { 62 | ((NTTStrategyDecorator) this).afterTransform(arrayAccess); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/IntModConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various modular arithmetic operations for the int type. 28 | * 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public interface IntModConstants 34 | { 35 | /** 36 | * Moduli to be used in number theoretic transforms. 37 | * Allows transform lengths upto 3*224. 38 | */ 39 | 40 | public static final int MODULUS[] = { 2113929217, 2013265921, 1811939329 }; 41 | 42 | /** 43 | * Primitive roots for the corresponding moduli. 44 | */ 45 | 46 | public static final int PRIMITIVE_ROOT[] = { 5, 31, 13 }; 47 | 48 | /** 49 | * Maximum transform length for the moduli. 50 | */ 51 | 52 | public static final long MAX_TRANSFORM_LENGTH = 50331648; 53 | 54 | /** 55 | * Maximum bits in a power-of-two base that fits in an int. 56 | */ 57 | 58 | public static final int MAX_POWER_OF_TWO_BITS = 31; 59 | 60 | /** 61 | * Maximum power-of-two base that fits in an int. 62 | */ 63 | 64 | public static final int MAX_POWER_OF_TWO_BASE = 1 << MAX_POWER_OF_TWO_BITS; 65 | } 66 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/CarryCRTBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | /** 27 | * Interface of a factory for creating carry-CRT related objects. 28 | * The factory method pattern is used. 29 | * 30 | * @param The element array type of the CRT. 31 | * 32 | * @see CarryCRTStrategy 33 | * @see CarryCRTStepStrategy 34 | * 35 | * @since 1.7.0 36 | * @version 1.7.0 37 | * @author Mikko Tommila 38 | */ 39 | 40 | public interface CarryCRTBuilder 41 | { 42 | /** 43 | * Creates an object for implementing the carry-CRT of a three-NTT 44 | * based convolution using the specified radix. 45 | * 46 | * @param radix The radix that will be used. 47 | * 48 | * @return A suitable object for performing the carry-CRT. 49 | */ 50 | 51 | public CarryCRTStrategy createCarryCRT(int radix); 52 | 53 | /** 54 | * Creates an object for implementing the steps of the carry-CRT 55 | * of a three-NTT based convolution using the specified radix. 56 | * 57 | * @param radix The radix that will be used. 58 | * 59 | * @return A suitable object for performing the carry-CRT steps. 60 | */ 61 | 62 | public CarryCRTStepStrategy createCarryCRTSteps(int radix); 63 | } 64 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/FloatModConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various modular arithmetic operations for the float type. 28 | * 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public interface FloatModConstants 34 | { 35 | /** 36 | * Moduli to be used in number theoretic transforms. 37 | * Allows transform lengths upto 3*217. 38 | */ 39 | 40 | public static final float MODULUS[] = { 16515073.0f, 14942209.0f, 14155777.0f }; 41 | 42 | /** 43 | * Primitive roots for the corresponding moduli. 44 | */ 45 | 46 | public static final float PRIMITIVE_ROOT[] = { 5.0f, 11.0f, 7.0f }; 47 | 48 | /** 49 | * Maximum transform length for the moduli. 50 | */ 51 | 52 | public static final long MAX_TRANSFORM_LENGTH = 393216; 53 | 54 | /** 55 | * Maximum bits in a power-of-two base that fits in a float. 56 | */ 57 | 58 | public static final int MAX_POWER_OF_TWO_BITS = 24; 59 | 60 | /** 61 | * Maximum power-of-two base that fits in a float. 62 | */ 63 | 64 | public static final float MAX_POWER_OF_TWO_BASE = (float) (1 << MAX_POWER_OF_TWO_BITS); 65 | } 66 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeScramble.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Functions to perform bit-reverse ordering of rawtype data. 28 | * 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public class RawtypeScramble 34 | { 35 | private RawtypeScramble() 36 | { 37 | } 38 | 39 | /** 40 | * Permute the data in the table to bit-reversed order.

41 | * 42 | * The permutation table argument should contain pairs of indexes 43 | * that indicate array elements whose contents are swapped. 44 | * 45 | * @param data The array to permute. 46 | * @param offset The offset within the array to permute. 47 | * @param permutationTable Table of indexes indicating, which elements in the data are to be swapped. 48 | */ 49 | 50 | public static void scramble(rawtype[] data, int offset, int[] permutationTable) 51 | { 52 | for (int k = 0; k < permutationTable.length; k += 2) 53 | { 54 | int i = offset + permutationTable[k], 55 | j = offset + permutationTable[k + 1]; 56 | rawtype tmp = data[i]; 57 | data[i] = data[j]; 58 | data[j] = tmp; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/LongModConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various modular arithmetic operations for the long type. 28 | * 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public interface LongModConstants 34 | { 35 | /** 36 | * Moduli to be used in number theoretic transforms. 37 | * Allows transform lengths upto 3*247. 38 | */ 39 | 40 | public static final long MODULUS[] = { 136796838681378817L, 127508164449927169L, 119063915148607489L }; 41 | 42 | /** 43 | * Primitive roots for the corresponding moduli. 44 | */ 45 | 46 | public static final long PRIMITIVE_ROOT[] = { 5, 14, 26 }; 47 | 48 | /** 49 | * Maximum transform length for the moduli. 50 | */ 51 | 52 | public static final long MAX_TRANSFORM_LENGTH = 422212465065984L; 53 | 54 | /** 55 | * Maximum bits in a power-of-two base that fits in a long. 56 | */ 57 | 58 | public static final int MAX_POWER_OF_TWO_BITS = 57; 59 | 60 | /** 61 | * Maximum power-of-two base that fits in a long. 62 | */ 63 | 64 | public static final long MAX_POWER_OF_TWO_BASE = 1L << MAX_POWER_OF_TWO_BITS; 65 | } 66 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/internal/DoubleModConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | /** 27 | * Constants needed for various modular arithmetic operations for the double type. 28 | * 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public interface DoubleModConstants 34 | { 35 | /** 36 | * Moduli to be used in number theoretic transforms. 37 | * Allows transform lengths upto 3*243. 38 | */ 39 | 40 | public static final double MODULUS[] = { 1952732650930177.0, 1899956092796929.0, 1636073302130689.0 }; 41 | 42 | /** 43 | * Primitive roots for the corresponding moduli. 44 | */ 45 | 46 | public static final double PRIMITIVE_ROOT[] = { 5.0, 7.0, 17.0 }; 47 | 48 | /** 49 | * Maximum transform length for the moduli. 50 | */ 51 | 52 | public static final long MAX_TRANSFORM_LENGTH = 26388279066624L; 53 | 54 | /** 55 | * Maximum bits in a power-of-two base that fits in a double. 56 | */ 57 | 58 | public static final int MAX_POWER_OF_TWO_BITS = 51; 59 | 60 | /** 61 | * Maximum power-of-two base that fits in a double. 62 | */ 63 | 64 | public static final double MAX_POWER_OF_TWO_BASE = (double) (1L << MAX_POWER_OF_TWO_BITS); 65 | } 66 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/ExecutionStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | import java.util.concurrent.Future; 27 | 28 | /** 29 | * Thread execution operations. 30 | * 31 | * @since 1.9.0 32 | * @version 1.9.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public interface ExecutionStrategy 37 | { 38 | /** 39 | * While waiting for a Future to be completed, steal work 40 | * from any running tasks and run it.

41 | * 42 | * While this method may functionally appear to be equivalent to just 43 | * calling future.get() it should try its best to steal 44 | * work from any other tasks submitted to the ExecutorService 45 | * of the current ApfloatContext. It may in fact steal 46 | * work using multiple threads, if the current ApfloatContext 47 | * specifies numberOfProcessors to be more than one.

48 | * 49 | * The purpose of this method is to allow keeping all threads of the 50 | * ExecutorService (and CPU cores) maximally busy at all 51 | * times, while also not running an excessive number of parallel 52 | * threads (only as many threads as there are CPU cores). 53 | * 54 | * @param future The Future to wait for. 55 | */ 56 | 57 | public void wait(Future future); 58 | } 59 | -------------------------------------------------------------------------------- /apfloat/src/test/java/org/apfloat/ShutdownMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import java.util.Map; 27 | 28 | import junit.framework.TestCase; 29 | import junit.framework.TestSuite; 30 | 31 | /** 32 | * @version 1.9.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class ShutdownMapTest 37 | extends TestCase 38 | { 39 | public ShutdownMapTest(String methodName) 40 | { 41 | super(methodName); 42 | } 43 | 44 | public static void main(String[] args) 45 | { 46 | junit.textui.TestRunner.run(suite()); 47 | } 48 | 49 | public static TestSuite suite() 50 | { 51 | TestSuite suite = new TestSuite(); 52 | 53 | suite.addTest(new ShutdownMapTest("testMap")); 54 | 55 | return suite; 56 | } 57 | 58 | public static void testMap() 59 | { 60 | Map map = new ShutdownMap<>(); 61 | 62 | try 63 | { 64 | map.put(0, Apfloat.ZERO); 65 | fail("ShutdownMap allowed put()"); 66 | } 67 | catch (ApfloatRuntimeException are) 68 | { 69 | // OK 70 | } 71 | 72 | try 73 | { 74 | map.get(0); 75 | fail("ShutdownMap allowed get()"); 76 | } 77 | catch (ApfloatRuntimeException are) 78 | { 79 | // OK 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/ConvolutionStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | import org.apfloat.ApfloatRuntimeException; 27 | 28 | /** 29 | * Generic convolution strategy. To perform the convolution, 30 | * an implementing class could use e.g. 31 | * 32 | *

38 | * 39 | * @version 1.0 40 | * @author Mikko Tommila 41 | */ 42 | 43 | public interface ConvolutionStrategy 44 | { 45 | /** 46 | * Convolutes the two sets of data. 47 | * 48 | * @param x First data set. 49 | * @param y Second data set. 50 | * @param resultSize Number of elements needed in the result data. 51 | * 52 | * @return The convolved data. 53 | */ 54 | 55 | public DataStorage convolute(DataStorage x, DataStorage y, long resultSize) 56 | throws ApfloatRuntimeException; 57 | } 58 | -------------------------------------------------------------------------------- /apfloat-samples/src/main/java/org/apfloat/samples/OperationExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.samples; 25 | 26 | /** 27 | * Interface for implementing objects that can execute {@link Operation}s. 28 | * An operation can e.g. be executed locally or remotely. 29 | * 30 | * @version 1.1 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public interface OperationExecutor 35 | { 36 | /** 37 | * Executes some code, returning a value. 38 | * 39 | * @param Return value type of the operation. 40 | * @param operation The operation to execute. 41 | * 42 | * @return Return value of the operation. 43 | */ 44 | 45 | public T execute(Operation operation); 46 | 47 | /** 48 | * Starts executing some code in the background. 49 | * 50 | * @param Return value type of the operation. 51 | * @param operation The operation to execute in the background. 52 | * 53 | * @return An object for retrieving the result of the operation later. 54 | */ 55 | 56 | public BackgroundOperation executeBackground(Operation operation); 57 | 58 | /** 59 | * Returns the relative weight of this executor. 60 | * The weights of different operation executors can be used 61 | * to distribute work more equally. 62 | * 63 | * @return The relative weight of this operation executor. 64 | */ 65 | 66 | public int getWeight(); 67 | } 68 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeNTTBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.NTTStrategy; 27 | import org.apfloat.spi.NTTStepStrategy; 28 | import org.apfloat.spi.Factor3NTTStepStrategy; 29 | import org.apfloat.spi.NTTConvolutionStepStrategy; 30 | 31 | /** 32 | * Creates Number Theoretic Transforms for the 33 | * rawtype type. 34 | * 35 | * @see RawtypeTableFNTStrategy 36 | * @see SixStepFNTStrategy 37 | * @see TwoPassFNTStrategy 38 | * @see Factor3NTTStrategy 39 | * 40 | * @version 1.8.3 41 | * @author Mikko Tommila 42 | */ 43 | 44 | public class RawtypeNTTBuilder 45 | extends AbstractNTTBuilder 46 | { 47 | /** 48 | * Default constructor. 49 | */ 50 | 51 | public RawtypeNTTBuilder() 52 | { 53 | } 54 | 55 | @Override 56 | public NTTStepStrategy createNTTSteps() 57 | { 58 | return new RawtypeNTTStepStrategy(); 59 | } 60 | 61 | @Override 62 | public NTTConvolutionStepStrategy createNTTConvolutionSteps() 63 | { 64 | return new RawtypeNTTConvolutionStepStrategy(); 65 | } 66 | 67 | @Override 68 | public Factor3NTTStepStrategy createFactor3NTTSteps() 69 | { 70 | return new RawtypeFactor3NTTStepStrategy(); 71 | } 72 | 73 | @Override 74 | protected NTTStrategy createSimpleFNTStrategy(long size) 75 | { 76 | return new RawtypeTableFNTStrategy(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /apfloat-calc/src/main/java/org/apfloat/calc/CalculatorGUI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.calc; 25 | 26 | import java.awt.Frame; 27 | import java.awt.BorderLayout; 28 | import java.awt.Label; 29 | import java.awt.event.WindowAdapter; 30 | import java.awt.event.WindowEvent; 31 | 32 | /** 33 | * AWT client application for the calculator. 34 | * 35 | * @version 1.9.0 36 | * @author Mikko Tommila 37 | */ 38 | 39 | public class CalculatorGUI 40 | extends Frame 41 | { 42 | private static final long serialVersionUID = 1L; 43 | 44 | /** 45 | * Default constructor. 46 | */ 47 | 48 | protected CalculatorGUI() 49 | { 50 | super("Calculator"); 51 | setSize(720, 540); 52 | 53 | addWindowListener(new WindowAdapter() 54 | { 55 | @Override 56 | public void windowClosing(WindowEvent windowEvent) 57 | { 58 | setVisible(false); 59 | dispose(); 60 | System.exit(0); 61 | } 62 | }); 63 | 64 | setLayout(new BorderLayout()); 65 | 66 | add(new CalculatorAWT(), BorderLayout.NORTH); 67 | add(new Label(), BorderLayout.SOUTH); 68 | 69 | setVisible(true); 70 | } 71 | 72 | /** 73 | * Command-line entry point. 74 | * 75 | * @param args Command-line parameters. 76 | */ 77 | 78 | public static void main(String[] args) 79 | { 80 | new CalculatorGUI(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /apfloat/src/test/template/org/apfloat/internal/RawtypeMemoryDataStorageTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.*; 27 | import org.apfloat.spi.*; 28 | 29 | import junit.framework.TestCase; 30 | import junit.framework.TestSuite; 31 | 32 | /** 33 | * @version 1.7.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class RawtypeMemoryDataStorageTest 38 | extends RawtypeDataStorageTestCase 39 | { 40 | private RawtypeMemoryDataStorageTest() 41 | { 42 | } 43 | 44 | public RawtypeMemoryDataStorageTest(String methodName) 45 | { 46 | super(methodName); 47 | } 48 | 49 | public static void main(String[] args) 50 | { 51 | junit.textui.TestRunner.run(suite()); 52 | } 53 | 54 | public static TestSuite suite() 55 | { 56 | TestSuite suite = new RawtypeMemoryDataStorageTest().realSuite(); 57 | 58 | suite.addTest(new RawtypeDiskDataStorageTest("testIsCached")); 59 | 60 | return suite; 61 | } 62 | 63 | @Override 64 | public TestCase createTestCase(String methodName) 65 | { 66 | return new RawtypeMemoryDataStorageTest(methodName); 67 | } 68 | 69 | @Override 70 | public DataStorage createDataStorage() 71 | throws ApfloatRuntimeException 72 | { 73 | return new RawtypeMemoryDataStorage(); 74 | } 75 | 76 | public static void testIsCached() 77 | { 78 | assertTrue(new RawtypeDiskDataStorage().isCached()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /apfloat/src/test/template/org/apfloat/internal/RawtypeScrambleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import junit.framework.TestSuite; 27 | 28 | /** 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public class RawtypeScrambleTest 34 | extends RawtypeTestCase 35 | { 36 | public RawtypeScrambleTest(String methodName) 37 | { 38 | super(methodName); 39 | } 40 | 41 | public static void main(String[] args) 42 | { 43 | junit.textui.TestRunner.run(suite()); 44 | } 45 | 46 | public static TestSuite suite() 47 | { 48 | TestSuite suite = new TestSuite(); 49 | 50 | suite.addTest(new RawtypeScrambleTest("testScramble")); 51 | 52 | return suite; 53 | } 54 | 55 | public static void testScramble() 56 | { 57 | int[] permutationTable = Scramble.createScrambleTable(8); 58 | rawtype[] ints = { (rawtype) -1, (rawtype) 0, (rawtype) 1, (rawtype) 2, (rawtype) 3, (rawtype) 4, (rawtype) 5, (rawtype) 6, (rawtype) 7 }; 59 | RawtypeScramble.scramble(ints, 1, permutationTable); 60 | assertEquals("[0]", 0, (int) ints[1]); 61 | assertEquals("[1]", 4, (int) ints[2]); 62 | assertEquals("[2]", 2, (int) ints[3]); 63 | assertEquals("[3]", 6, (int) ints[4]); 64 | assertEquals("[4]", 1, (int) ints[5]); 65 | assertEquals("[5]", 5, (int) ints[6]); 66 | assertEquals("[6]", 3, (int) ints[7]); 67 | assertEquals("[7]", 7, (int) ints[8]); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /apfloat-samples/src/main/java/org/apfloat/samples/ApfloatHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.samples; 25 | 26 | import java.io.Serializable; 27 | 28 | import org.apfloat.Apfloat; 29 | 30 | /** 31 | * Simple JavaBean to hold one {@link org.apfloat.Apfloat}. 32 | * This class can also be thought of as a pointer to an {@link Apfloat}. 33 | * 34 | * @version 1.9.0 35 | * @author Mikko Tommila 36 | */ 37 | 38 | public class ApfloatHolder 39 | implements Serializable 40 | { 41 | /** 42 | * Construct an ApfloatHolder containing null. 43 | */ 44 | 45 | public ApfloatHolder() 46 | { 47 | this(null); 48 | } 49 | 50 | /** 51 | * Construct an ApfloatHolder containing the specified apfloat. 52 | * 53 | * @param apfloat The number to hold. 54 | */ 55 | 56 | public ApfloatHolder(Apfloat apfloat) 57 | { 58 | this.apfloat = apfloat; 59 | } 60 | 61 | /** 62 | * Return the apfloat contained in this bean. 63 | * 64 | * @return The apfloat contained in this bean. 65 | */ 66 | 67 | public Apfloat getApfloat() 68 | { 69 | return this.apfloat; 70 | } 71 | 72 | /** 73 | * Set the apfloat contained in this bean. 74 | * 75 | * @param apfloat The apfloat. 76 | */ 77 | 78 | public void setApfloat(Apfloat apfloat) 79 | { 80 | this.apfloat = apfloat; 81 | } 82 | 83 | private static final long serialVersionUID = 1L; 84 | 85 | private Apfloat apfloat; 86 | } 87 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/Factor3NTTStepStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | import org.apfloat.ApfloatRuntimeException; 27 | 28 | /** 29 | * Steps for the factor-3 NTT. 30 | * 31 | * @since 1.7.0 32 | * @version 1.7.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public interface Factor3NTTStepStrategy 37 | { 38 | /** 39 | * Transform the columns of a matrix using a 3-point transform. 40 | * 41 | * @param dataStorage0 The data of the first column. 42 | * @param dataStorage1 The data of the second column. 43 | * @param dataStorage2 The data of the third column. 44 | * @param startColumn The starting element index in the data storages to transform. 45 | * @param columns How many columns to transform. 46 | * @param power2length Length of the column transform. 47 | * @param length Length of total transform (three times the length of one column). 48 | * @param isInverse true if an inverse transform is performed, false if a forward transform is performed. 49 | * @param modulus Index of the modulus. 50 | */ 51 | 52 | public void transformColumns(DataStorage dataStorage0, DataStorage dataStorage1, DataStorage dataStorage2, long startColumn, long columns, long power2length, long length, boolean isInverse, int modulus) 53 | throws ApfloatRuntimeException; 54 | 55 | /** 56 | * Get the maximum transform length. 57 | * 58 | * @return The maximum transform length. 59 | */ 60 | 61 | public long getMaxTransformLength(); 62 | } 63 | -------------------------------------------------------------------------------- /apfloat-samples/src/main/java/org/apfloat/samples/LocalOperationExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.samples; 25 | 26 | /** 27 | * Class to execute {@link Operation}s locally. 28 | * The execution is done in the current JVM. 29 | * 30 | * @version 1.9.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class LocalOperationExecutor 35 | implements OperationExecutor 36 | { 37 | /** 38 | * Default constructor. 39 | */ 40 | 41 | public LocalOperationExecutor() 42 | { 43 | } 44 | 45 | /** 46 | * Execute an operation immediately. 47 | * This method will block until the operation is complete. 48 | * 49 | * @param operation The operation to execute. 50 | * 51 | * @return The result of the operation. 52 | */ 53 | 54 | @Override 55 | public T execute(Operation operation) 56 | { 57 | return operation.execute(); 58 | } 59 | 60 | /** 61 | * Execute an operation in the background. 62 | * This method starts a new thread executing the operation and returns immediately. 63 | * 64 | * @param operation The operation to execute in the background. 65 | * 66 | * @return A {@link BackgroundOperation} for retrieving the result of the operation later. 67 | */ 68 | 69 | @Override 70 | public BackgroundOperation executeBackground(Operation operation) 71 | { 72 | return new BackgroundOperation<>(operation); 73 | } 74 | 75 | @Override 76 | public int getWeight() 77 | { 78 | return 1; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/CarryCRTStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | import org.apfloat.ApfloatRuntimeException; 27 | 28 | /** 29 | * Interface for performing the final step of a three-modulus 30 | * Number Theoretic Transform based convolution. 31 | * 32 | * @since 1.7.0 33 | * @version 1.7.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public interface CarryCRTStrategy 38 | { 39 | /** 40 | * Calculate the final result of a three-NTT convolution.

41 | * 42 | * Performs a Chinese Remainder Theorem (CRT) on each element 43 | * of the three result data sets to get the result of each element 44 | * modulo the product of the three moduli. Then it calculates the carries 45 | * to get the final result.

46 | * 47 | * Note that the return value's initial word may be zero or non-zero, 48 | * depending on how large the result is.

49 | * 50 | * Assumes that MODULUS[0] > MODULUS[1] > MODULUS[2]. 51 | * 52 | * @param resultMod0 The result modulo MODULUS[0]. 53 | * @param resultMod1 The result modulo MODULUS[1]. 54 | * @param resultMod2 The result modulo MODULUS[2]. 55 | * @param resultSize The number of elements needed in the final result. 56 | * 57 | * @return The final result with the CRT performed and the carries calculated. 58 | */ 59 | 60 | public DataStorage carryCRT(DataStorage resultMod0, DataStorage resultMod1, DataStorage resultMod2, long resultSize) 61 | throws ApfloatRuntimeException; 62 | } 63 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeMemoryArrayAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.ApfloatRuntimeException; 27 | import org.apfloat.spi.ArrayAccess; 28 | 29 | /** 30 | * Array access class based on a rawtype[]. 31 | * 32 | * @version 1.6.3 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class RawtypeMemoryArrayAccess 37 | extends ArrayAccess 38 | { 39 | /** 40 | * Create an array access.

41 | * 42 | * @param data The underlying array. 43 | * @param offset The offset of the access segment within the array. 44 | * @param length The access segment. 45 | */ 46 | 47 | public RawtypeMemoryArrayAccess(rawtype[] data, int offset, int length) 48 | { 49 | super(offset, length); 50 | this.data = data; 51 | } 52 | 53 | @Override 54 | public ArrayAccess subsequence(int offset, int length) 55 | { 56 | return new RawtypeMemoryArrayAccess(this.data, getOffset() + offset, length); 57 | } 58 | 59 | @Override 60 | public Object getData() 61 | { 62 | return this.data; 63 | } 64 | 65 | @Override 66 | public rawtype[] getRawtypeData() 67 | { 68 | return this.data; 69 | } 70 | 71 | @Override 72 | public void close() 73 | throws ApfloatRuntimeException 74 | { 75 | this.data = null; // Might have an impact on garbage collection 76 | } 77 | 78 | private static final long serialVersionUID = ${org.apfloat.internal.RawtypeMemoryArrayAccess.serialVersionUID}; 79 | 80 | private rawtype[] data; 81 | } 82 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/NTTBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | /** 27 | * Interface of a factory for creating Number Theoretic Transforms. 28 | * The factory method pattern is used. 29 | * 30 | * @see NTTStrategy 31 | * @see NTTStepStrategy 32 | * 33 | * @version 1.7.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public interface NTTBuilder 38 | { 39 | /** 40 | * Creates a Number Theoretic Transform of suitable 41 | * type for the specified length. 42 | * 43 | * @param size The transform length that will be used. 44 | * 45 | * @return A suitable NTT object for performing the transform. 46 | */ 47 | 48 | public NTTStrategy createNTT(long size); 49 | 50 | /** 51 | * Creates an object for implementing the steps of a step-based 52 | * Number Theoretic Transform. 53 | * 54 | * @return A suitable object for performing the transform steps. 55 | * 56 | * @since 1.7.0 57 | */ 58 | 59 | public NTTStepStrategy createNTTSteps(); 60 | 61 | /** 62 | * Creates an object for implementing the steps of a three-NTT 63 | * based convolution. 64 | * 65 | * @return A suitable object for performing the convolution steps. 66 | * 67 | * @since 1.7.0 68 | */ 69 | 70 | public NTTConvolutionStepStrategy createNTTConvolutionSteps(); 71 | 72 | /** 73 | * Creates an object for implementing the steps of factor-3 NTT. 74 | * 75 | * @return A suitable object for performing the factor-3 NTT steps. 76 | * 77 | * @since 1.7.0 78 | */ 79 | 80 | public Factor3NTTStepStrategy createFactor3NTTSteps(); 81 | } 82 | -------------------------------------------------------------------------------- /apfloat-jscience/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.apfloat 7 | apfloat-parent 8 | 1.15.1-SNAPSHOT 9 | 10 | 11 | apfloat-jscience 12 | 13 | apfloat-jscience 14 | JScience wrapper for apfloat 15 | https://www.apfloat.org 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.apfloat 23 | apfloat 24 | 25 | 26 | org.jscience 27 | jscience 28 | 29 | 30 | junit 31 | junit 32 | test 33 | 34 | 35 | org.apfloat 36 | apfloat 37 | test-jar 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | biz.aQute.bnd 46 | bnd-maven-plugin 47 | 48 | 49 | generate-osgi-manifest 50 | 51 | bnd-process 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-jar-plugin 59 | 60 | 61 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-shade-plugin 68 | 69 | 70 | 71 | shade 72 | 73 | 74 | 75 | 76 | org.apfloat:apfloat-jscience 77 | 78 | 79 | ${project.build.directory}/apfloat-jscience.jar 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /apfloat-aparapi/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.apfloat 7 | apfloat-parent 8 | 1.15.1-SNAPSHOT 9 | 10 | 11 | apfloat-aparapi 12 | 13 | apfloat-aparapi 14 | Fast number theoretic transform implementation using Aparapi 15 | https://www.apfloat.org 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.apfloat 23 | apfloat 24 | 25 | 26 | com.aparapi 27 | aparapi 28 | 29 | 30 | junit 31 | junit 32 | test 33 | 34 | 35 | org.apfloat 36 | apfloat 37 | test-jar 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | biz.aQute.bnd 46 | bnd-maven-plugin 47 | 48 | 49 | generate-osgi-manifest 50 | 51 | bnd-process 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-jar-plugin 59 | 60 | 61 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-shade-plugin 68 | 69 | 70 | 71 | shade 72 | 73 | 74 | 75 | 76 | org.apfloat:apfloat-aparapi 77 | 78 | 79 | ${project.build.directory}/apfloat-aparapi.jar 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeDataStorageBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.ApfloatContext; 27 | import org.apfloat.ApfloatRuntimeException; 28 | import org.apfloat.spi.DataStorage; 29 | 30 | /** 31 | * Default data storage creation strategy for the rawtype data type. 32 | * 33 | * @see RawtypeMemoryDataStorage 34 | * @see RawtypeDiskDataStorage 35 | * 36 | * @version 1.15.0 37 | * @author Mikko Tommila 38 | */ 39 | 40 | public class RawtypeDataStorageBuilder 41 | extends AbstractDataStorageBuilder 42 | { 43 | /** 44 | * Default constructor. 45 | */ 46 | 47 | public RawtypeDataStorageBuilder() 48 | { 49 | } 50 | 51 | @Override 52 | protected long getMaxCachedSize() 53 | { 54 | return (long) RawType.BYTES * Integer.MAX_VALUE; 55 | } 56 | 57 | @Override 58 | protected DataStorage createCachedDataStorage() 59 | throws ApfloatRuntimeException 60 | { 61 | return new RawtypeMemoryDataStorage(); 62 | } 63 | 64 | @Override 65 | protected DataStorage createNonCachedDataStorage() 66 | throws ApfloatRuntimeException 67 | { 68 | ApfloatContext ctx = ApfloatContext.getContext(); 69 | if (!ctx.getCleanupAtExit()) 70 | { 71 | throw new BackingStorageException("Not allowed to use file storage", "file.allow"); 72 | } 73 | return new RawtypeDiskDataStorage(); 74 | } 75 | 76 | @Override 77 | protected boolean isCached(DataStorage dataStorage) 78 | throws ApfloatRuntimeException 79 | { 80 | return (dataStorage instanceof RawtypeMemoryDataStorage); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/NTTConvolutionStepStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | import org.apfloat.ApfloatRuntimeException; 27 | 28 | /** 29 | * Steps for a three-NTT convolution. This includes element-by-element 30 | * multiplication and squaring of the transformed data. 31 | * 32 | * @since 1.7.0 33 | * @version 1.7.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public interface NTTConvolutionStepStrategy 38 | { 39 | /** 40 | * Linear multiplication in the number theoretic domain. 41 | * The operation is sourceAndDestination[i] *= source[i] (mod m).

42 | * 43 | * For maximum performance, sourceAndDestination 44 | * should be in memory if possible. 45 | * 46 | * @param sourceAndDestination The first source data storage, which is also the destination. 47 | * @param source The second source data storage. 48 | * @param modulus Which modulus to use (0, 1, 2) 49 | */ 50 | 51 | public void multiplyInPlace(DataStorage sourceAndDestination, DataStorage source, int modulus) 52 | throws ApfloatRuntimeException; 53 | 54 | /** 55 | * Linear squaring in the number theoretic domain. 56 | * The operation is sourceAndDestination[i] *= sourceAndDestination[i] (mod m).

57 | * 58 | * For maximum performance, sourceAndDestination 59 | * should be in memory if possible. 60 | * 61 | * @param sourceAndDestination The source data storage, which is also the destination. 62 | * @param modulus Which modulus to use (0, 1, 2) 63 | */ 64 | 65 | public void squareInPlace(DataStorage sourceAndDestination, int modulus) 66 | throws ApfloatRuntimeException; 67 | } 68 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/test/java/org/apfloat/aparapi/IntAparapiTwoPassFNTStrategyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.*; 27 | import org.apfloat.spi.*; 28 | import org.apfloat.internal.*; 29 | 30 | import junit.framework.TestSuite; 31 | 32 | /** 33 | * @version 1.15.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class IntAparapiTwoPassFNTStrategyTest 38 | extends IntNTTStrategyTestCase 39 | { 40 | public IntAparapiTwoPassFNTStrategyTest(String methodName) 41 | { 42 | super(methodName); 43 | } 44 | 45 | public static void main(String[] args) 46 | { 47 | junit.textui.TestRunner.run(suite()); 48 | } 49 | 50 | public static TestSuite suite() 51 | { 52 | TestSuite suite = new TestSuite(); 53 | 54 | suite.addTest(new IntAparapiTwoPassFNTStrategyTest("testRoundTrip")); 55 | suite.addTest(new IntAparapiTwoPassFNTStrategyTest("testRoundTripBig")); 56 | 57 | return suite; 58 | } 59 | 60 | public static void testRoundTrip() 61 | { 62 | ApfloatContext ctx = ApfloatContext.getContext(); 63 | 64 | ctx.setMaxMemoryBlockSize(65536); 65 | ctx.setMemoryThreshold(1024); 66 | ctx.setBlockSize(256); 67 | runRoundTrip(131072); 68 | } 69 | 70 | public static void testRoundTripBig() 71 | { 72 | ApfloatContext ctx = ApfloatContext.getContext(); 73 | 74 | ctx.setMaxMemoryBlockSize(65536); 75 | ctx.setMemoryThreshold(1024); 76 | ctx.setBlockSize(256); 77 | int size = (int) Math.min(1 << 21, Util.round2down(IntModConstants.MAX_TRANSFORM_LENGTH)); 78 | runRoundTrip(size); 79 | } 80 | 81 | private static void runRoundTrip(int size) 82 | { 83 | runRoundTrip(new IntAparapiTwoPassFNTStrategy(), size); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeApfloatBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import java.io.PushbackReader; 27 | import java.io.IOException; 28 | 29 | import org.apfloat.ApfloatRuntimeException; 30 | import org.apfloat.spi.ApfloatBuilder; 31 | import org.apfloat.spi.ApfloatImpl; 32 | 33 | /** 34 | * Builder class for building {@link ApfloatImpl} implementations with the 35 | * rawtype data element type. 36 | * 37 | * @version 1.0 38 | * @author Mikko Tommila 39 | */ 40 | 41 | public class RawtypeApfloatBuilder 42 | implements ApfloatBuilder 43 | { 44 | /** 45 | * Default constructor. 46 | */ 47 | 48 | public RawtypeApfloatBuilder() 49 | { 50 | } 51 | 52 | @Override 53 | public ApfloatImpl createApfloat(String value, long precision, int radix, boolean isInteger) 54 | throws NumberFormatException, ApfloatRuntimeException 55 | { 56 | return new RawtypeApfloatImpl(value, precision, radix, isInteger); 57 | } 58 | 59 | @Override 60 | public ApfloatImpl createApfloat(long value, long precision, int radix) 61 | throws NumberFormatException, ApfloatRuntimeException 62 | { 63 | return new RawtypeApfloatImpl(value, precision, radix); 64 | } 65 | 66 | @Override 67 | public ApfloatImpl createApfloat(double value, long precision, int radix) 68 | throws NumberFormatException, ApfloatRuntimeException 69 | { 70 | return new RawtypeApfloatImpl(value, precision, radix); 71 | } 72 | 73 | @Override 74 | public ApfloatImpl createApfloat(PushbackReader in, long precision, int radix, boolean isInteger) 75 | throws IOException, NumberFormatException, ApfloatRuntimeException 76 | { 77 | return new RawtypeApfloatImpl(in, precision, radix, isInteger); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/test/java/org/apfloat/aparapi/LongAparapiTwoPassFNTStrategyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.*; 27 | import org.apfloat.spi.*; 28 | import org.apfloat.internal.*; 29 | 30 | import junit.framework.TestSuite; 31 | 32 | /** 33 | * @version 1.15.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class LongAparapiTwoPassFNTStrategyTest 38 | extends LongNTTStrategyTestCase 39 | { 40 | public LongAparapiTwoPassFNTStrategyTest(String methodName) 41 | { 42 | super(methodName); 43 | } 44 | 45 | public static void main(String[] args) 46 | { 47 | junit.textui.TestRunner.run(suite()); 48 | } 49 | 50 | public static TestSuite suite() 51 | { 52 | TestSuite suite = new TestSuite(); 53 | 54 | suite.addTest(new LongAparapiTwoPassFNTStrategyTest("testRoundTrip")); 55 | suite.addTest(new LongAparapiTwoPassFNTStrategyTest("testRoundTripBig")); 56 | 57 | return suite; 58 | } 59 | 60 | public static void testRoundTrip() 61 | { 62 | ApfloatContext ctx = ApfloatContext.getContext(); 63 | 64 | ctx.setMaxMemoryBlockSize(65536); 65 | ctx.setMemoryThreshold(1024); 66 | ctx.setBlockSize(256); 67 | runRoundTrip(131072); 68 | } 69 | 70 | public static void testRoundTripBig() 71 | { 72 | ApfloatContext ctx = ApfloatContext.getContext(); 73 | 74 | ctx.setMaxMemoryBlockSize(65536); 75 | ctx.setMemoryThreshold(1024); 76 | ctx.setBlockSize(256); 77 | int size = (int) Math.min(1 << 21, Util.round2down(LongModConstants.MAX_TRANSFORM_LENGTH)); 78 | runRoundTrip(size); 79 | } 80 | 81 | private static void runRoundTrip(int size) 82 | { 83 | runRoundTrip(new LongAparapiTwoPassFNTStrategy(), size); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /apfloat/src/test/template/org/apfloat/internal/RawtypeConvolutionStrategyTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.*; 27 | import org.apfloat.spi.*; 28 | 29 | /** 30 | * @version 1.9.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public abstract class RawtypeConvolutionStrategyTestCase 35 | extends RawtypeTestCase 36 | implements RawtypeRadixConstants 37 | { 38 | protected RawtypeConvolutionStrategyTestCase(String methodName) 39 | { 40 | super(methodName); 41 | } 42 | 43 | protected static DataStorage createDataStorage(rawtype[] data) 44 | { 45 | int size = data.length; 46 | ApfloatContext ctx = ApfloatContext.getContext(); 47 | DataStorageBuilder dataStorageBuilder = ctx.getBuilderFactory().getDataStorageBuilder(); 48 | DataStorage dataStorage = dataStorageBuilder.createDataStorage(size * RawType.BYTES); 49 | dataStorage.setSize(size); 50 | 51 | try (ArrayAccess arrayAccess = dataStorage.getArray(DataStorage.WRITE, 0, size)) 52 | { 53 | System.arraycopy(data, 0, arrayAccess.getData(), arrayAccess.getOffset(), size); 54 | } 55 | 56 | return dataStorage; 57 | } 58 | 59 | protected static void check(String message, int radix, rawtype[] expected, DataStorage actual) 60 | { 61 | try (ArrayAccess arrayAccess = actual.getArray(DataStorage.READ, 0, expected.length)) 62 | { 63 | assertEquals("radix " + radix + " " + message + " length", expected.length, arrayAccess.getLength()); 64 | for (int i = 0; i < arrayAccess.getLength(); i++) 65 | { 66 | assertEquals("radix " + radix + " " + message + " [" + i + "]", (long) expected[i], (long) arrayAccess.getRawtypeData()[arrayAccess.getOffset() + i]); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/ConcurrentSoftHashMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import java.lang.ref.SoftReference; 27 | import java.util.AbstractMap; 28 | import java.util.Map; 29 | import java.util.Set; 30 | import java.util.concurrent.ConcurrentHashMap; 31 | 32 | /** 33 | * Map with an underlying ConcurrentHashMap with softly referenced values. 34 | * The maximum map size is assumed to be limited so no effort is made to 35 | * expunge entries for stale values. 36 | * 37 | * @since 1.6 38 | * @version 1.9.0 39 | * @author Mikko Tommila 40 | */ 41 | 42 | class ConcurrentSoftHashMap 43 | extends AbstractMap 44 | { 45 | private ConcurrentHashMap> map; 46 | 47 | public ConcurrentSoftHashMap() 48 | { 49 | this.map = new ConcurrentHashMap<>(); 50 | } 51 | 52 | @Override 53 | public void clear() 54 | { 55 | this.map.clear(); 56 | } 57 | 58 | @Override 59 | public Set> entrySet() 60 | { 61 | throw new UnsupportedOperationException(); 62 | } 63 | 64 | @Override 65 | public V get(Object key) 66 | { 67 | return unwrap(this.map.get(key)); 68 | } 69 | 70 | @Override 71 | public V put(K key, V value) 72 | { 73 | return unwrap(this.map.put(key, wrap(value))); 74 | } 75 | 76 | @Override 77 | public V remove(Object key) 78 | { 79 | return unwrap(this.map.remove(key)); 80 | } 81 | 82 | @Override 83 | public int size() 84 | { 85 | return this.map.size(); 86 | } 87 | 88 | private SoftReference wrap(V value) 89 | { 90 | return new SoftReference<>(value); 91 | } 92 | 93 | private V unwrap(SoftReference value) 94 | { 95 | return (value == null ? null : value.get()); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/test/java/org/apfloat/aparapi/IntAparapiColumnTwoPassFNTStrategyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.*; 27 | import org.apfloat.spi.*; 28 | import org.apfloat.internal.*; 29 | 30 | import junit.framework.TestSuite; 31 | 32 | /** 33 | * @version 1.15.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class IntAparapiColumnTwoPassFNTStrategyTest 38 | extends IntNTTStrategyTestCase 39 | { 40 | public IntAparapiColumnTwoPassFNTStrategyTest(String methodName) 41 | { 42 | super(methodName); 43 | } 44 | 45 | public static void main(String[] args) 46 | { 47 | junit.textui.TestRunner.run(suite()); 48 | } 49 | 50 | public static TestSuite suite() 51 | { 52 | TestSuite suite = new TestSuite(); 53 | 54 | suite.addTest(new IntAparapiColumnTwoPassFNTStrategyTest("testRoundTrip")); 55 | suite.addTest(new IntAparapiColumnTwoPassFNTStrategyTest("testRoundTripBig")); 56 | 57 | return suite; 58 | } 59 | 60 | public static void testRoundTrip() 61 | { 62 | ApfloatContext ctx = ApfloatContext.getContext(); 63 | 64 | ctx.setMaxMemoryBlockSize(65536); 65 | ctx.setMemoryThreshold(1024); 66 | ctx.setBlockSize(256); 67 | runRoundTrip(131072); 68 | } 69 | 70 | public static void testRoundTripBig() 71 | { 72 | ApfloatContext ctx = ApfloatContext.getContext(); 73 | 74 | ctx.setMaxMemoryBlockSize(65536); 75 | ctx.setMemoryThreshold(1024); 76 | ctx.setBlockSize(256); 77 | int size = (int) Math.min(1 << 21, Util.round2down(IntModConstants.MAX_TRANSFORM_LENGTH)); 78 | runRoundTrip(size); 79 | } 80 | 81 | private static void runRoundTrip(int size) 82 | { 83 | runRoundTrip(new IntAparapiColumnTwoPassFNTStrategy(), size); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/test/java/org/apfloat/aparapi/LongAparapiColumnTwoPassFNTStrategyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.*; 27 | import org.apfloat.spi.*; 28 | import org.apfloat.internal.*; 29 | 30 | import junit.framework.TestSuite; 31 | 32 | /** 33 | * @version 1.15.0 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class LongAparapiColumnTwoPassFNTStrategyTest 38 | extends LongNTTStrategyTestCase 39 | { 40 | public LongAparapiColumnTwoPassFNTStrategyTest(String methodName) 41 | { 42 | super(methodName); 43 | } 44 | 45 | public static void main(String[] args) 46 | { 47 | junit.textui.TestRunner.run(suite()); 48 | } 49 | 50 | public static TestSuite suite() 51 | { 52 | TestSuite suite = new TestSuite(); 53 | 54 | suite.addTest(new LongAparapiColumnTwoPassFNTStrategyTest("testRoundTrip")); 55 | suite.addTest(new LongAparapiColumnTwoPassFNTStrategyTest("testRoundTripBig")); 56 | 57 | return suite; 58 | } 59 | 60 | public static void testRoundTrip() 61 | { 62 | ApfloatContext ctx = ApfloatContext.getContext(); 63 | 64 | ctx.setMaxMemoryBlockSize(65536); 65 | ctx.setMemoryThreshold(1024); 66 | ctx.setBlockSize(256); 67 | runRoundTrip(131072); 68 | } 69 | 70 | public static void testRoundTripBig() 71 | { 72 | ApfloatContext ctx = ApfloatContext.getContext(); 73 | 74 | ctx.setMaxMemoryBlockSize(65536); 75 | ctx.setMemoryThreshold(1024); 76 | ctx.setBlockSize(256); 77 | int size = (int) Math.min(1 << 21, Util.round2down(LongModConstants.MAX_TRANSFORM_LENGTH)); 78 | runRoundTrip(size); 79 | } 80 | 81 | private static void runRoundTrip(int size) 82 | { 83 | runRoundTrip(new LongAparapiColumnTwoPassFNTStrategy(), size); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/ApfloatLocalizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2024 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import java.text.MessageFormat; 27 | import java.util.MissingResourceException; 28 | import java.util.ResourceBundle; 29 | 30 | /** 31 | * Interface for exceptions that have localized messages. 32 | * 33 | * @since 1.15.0 34 | * @version 1.15.0 35 | * @author Mikko Tommila 36 | */ 37 | 38 | public interface ApfloatLocalizedException 39 | { 40 | /** 41 | * Returns the localized detail message. 42 | * 43 | * @return The localized detail message. 44 | */ 45 | 46 | default public String getLocalizedMessage() 47 | { 48 | String localizationKey = getLocalizationKey(); 49 | if (localizationKey == null) 50 | { 51 | return getMessage(); 52 | } 53 | String localizedMessage; 54 | try 55 | { 56 | String pattern = ResourceBundle.getBundle("org.apfloat.apfloat-exceptions").getString(localizationKey); 57 | localizedMessage = MessageFormat.format(pattern, getLocalizationArgs()); 58 | } 59 | catch (MissingResourceException mre) 60 | { 61 | localizedMessage = getMessage(); 62 | } 63 | return localizedMessage; 64 | } 65 | 66 | /** 67 | * Returns the detail message string of this throwable. 68 | * 69 | * @return The detail message string of this {@code Throwable} instance (which may be {@code null}). 70 | */ 71 | 72 | public String getMessage(); 73 | 74 | /** 75 | * Returns the localization key. 76 | * 77 | * @return The localization key. 78 | */ 79 | 80 | public String getLocalizationKey(); 81 | 82 | /** 83 | * Returns the localization arguments. 84 | * 85 | * @return The localization arguments. 86 | */ 87 | 88 | public Object[] getLocalizationArgs(); 89 | } 90 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/RootFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2024 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import java.util.function.BiFunction; 27 | import java.util.function.Function; 28 | 29 | import org.apfloat.spi.Util; 30 | 31 | /** 32 | * Helper class for finding roots of functions. 33 | * 34 | * @since 1.13.0 35 | * @version 1.13.0 36 | * @author Mikko Tommila 37 | */ 38 | 39 | class RootFinder 40 | { 41 | private RootFinder() 42 | { 43 | } 44 | 45 | /** 46 | * Find the root of the given function with Newton's method, starting from the given initial guess. 47 | * 48 | * @param f The function. 49 | * @param fp The derivative of the function, first argument is x, second argument is f(x) 50 | * @param y The function value to match (e.g. zero to find zeros, some other value to find inverses of functions) 51 | * @param initialGuess The initial guess 52 | * @param targetPrecision Target precision of the result 53 | * @return The root 54 | */ 55 | public static Apfloat findRoot(Function f, BiFunction fp, Apfloat y, Apfloat initialGuess, long targetPrecision) 56 | { 57 | Apfloat x = initialGuess; 58 | long workingPrecision = x.precision(), 59 | precision; 60 | do 61 | { 62 | Apfloat fn = f.apply(x), 63 | fpn = fp.apply(x, fn), 64 | d = fn.subtract(y).divide(fpn); 65 | precision = (d.signum() == 0 ? x.precision() : x.scale() - d.scale()); 66 | if (precision > 0) 67 | { 68 | workingPrecision = Math.min(targetPrecision, Math.max(workingPrecision, Util.ifFinite(precision, 2 * Util.ifFinite(precision, 2 * precision)))); 69 | } 70 | x = x.subtract(d).precision(workingPrecision); 71 | } while (precision < targetPrecision); 72 | 73 | return x.precision(targetPrecision); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /apfloat/src/test/template/org/apfloat/internal/RawtypeWTablesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import junit.framework.TestSuite; 27 | 28 | /** 29 | * @since 1.7.0 30 | * @version 1.7.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class RawtypeWTablesTest 35 | extends RawtypeTestCase 36 | implements RawtypeModConstants 37 | { 38 | public RawtypeWTablesTest(String methodName) 39 | { 40 | super(methodName); 41 | } 42 | 43 | public static void main(String[] args) 44 | { 45 | junit.textui.TestRunner.run(suite()); 46 | } 47 | 48 | public static TestSuite suite() 49 | { 50 | TestSuite suite = new TestSuite(); 51 | 52 | suite.addTest(new RawtypeWTablesTest("testGetWTable")); 53 | suite.addTest(new RawtypeWTablesTest("testGetInverseWTable")); 54 | 55 | return suite; 56 | } 57 | 58 | public static void testGetWTable() 59 | { 60 | rawtype[] wTable = RawtypeWTables.getWTable(0, 4); 61 | 62 | RawtypeModMath math = new RawtypeModMath(); 63 | math.setModulus(MODULUS[0]); 64 | assertEquals("[0]", 1, (long) wTable[0]); 65 | assertEquals("[1]", (long) MODULUS[0] - 1, (long) math.modPow(wTable[1], 2)); 66 | assertEquals("[2]", (long) MODULUS[0] - 1, (long) wTable[2]); 67 | assertEquals("[3]", (long) MODULUS[0] - 1, (long) math.modPow(wTable[3], 2)); 68 | } 69 | 70 | public static void testGetInverseWTable() 71 | { 72 | rawtype[] wTable = RawtypeWTables.getInverseWTable(0, 4); 73 | 74 | RawtypeModMath math = new RawtypeModMath(); 75 | math.setModulus(MODULUS[0]); 76 | assertEquals("[0]", 1, (long) wTable[0]); 77 | assertEquals("[1]", (long) MODULUS[0] - 1, (long) math.modPow(wTable[1], 2)); 78 | assertEquals("[2]", (long) MODULUS[0] - 1, (long) wTable[2]); 79 | assertEquals("[3]", (long) MODULUS[0] - 1, (long) math.modPow(wTable[3], 2)); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /apfloat-calc/src/main/java/org/apfloat/calc/Calculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.calc; 25 | 26 | /** 27 | * Command-line calculator. 28 | * 29 | * @version 1.11.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public class Calculator 34 | { 35 | private Calculator() 36 | { 37 | } 38 | 39 | /** 40 | * Command-line entry point. 41 | * 42 | * @param args Command-line parameters. 43 | * 44 | * @exception ParseException In case of invalid input 45 | */ 46 | 47 | public static void main(String args[]) 48 | throws ParseException 49 | { 50 | boolean pretty = false; 51 | Long inputPrecision = null; 52 | for (int i = 0; i < args.length; i++) 53 | { 54 | switch (args[i]) 55 | { 56 | case "-p": 57 | pretty = true; 58 | break; 59 | case "-i": 60 | try 61 | { 62 | i++; 63 | inputPrecision = Long.valueOf(args[i]); 64 | break; 65 | } 66 | catch (NumberFormatException | ArrayIndexOutOfBoundsException e) 67 | { 68 | // Fall through to usage 69 | } 70 | default: 71 | System.err.println("Usage: calculator [-p] [-i inputPrecision]"); 72 | System.exit(1); 73 | } 74 | } 75 | 76 | CalculatorImpl calculatorImpl = new ApfloatCalculatorImpl(); 77 | calculatorImpl.setFormat(pretty); 78 | calculatorImpl.setInputPrecision(inputPrecision); 79 | CalculatorParser calculatorParser = new CalculatorParser(System.in, System.out, calculatorImpl); 80 | while (calculatorParser.parseOneLine()) 81 | { 82 | // Loop until input ends or exception is thrown 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/main/java/org/apfloat/aparapi/RangeHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.spi.Util; 27 | 28 | import com.aparapi.Range; 29 | 30 | /** 31 | * Range helper methods. 32 | * 33 | * @since 1.11.0 34 | * @version 1.15.0 35 | * 36 | * @author Mikko Tommila 37 | */ 38 | 39 | class RangeHelper 40 | { 41 | // Note: it seems that this class is just a workaround to aparapi issue #171 where the local size is sometimes not set correctly 42 | // See: https://github.com/Syncleus/aparapi/issues/171 43 | 44 | private RangeHelper() 45 | { 46 | } 47 | 48 | /** 49 | * Creates a one-dimensional range with the maximum local size. 50 | * 51 | * @param size The size. 52 | * 53 | * @return The range. 54 | */ 55 | 56 | public static Range create(int size) 57 | { 58 | assert (size == (size & -size)); // Must be a power of two 59 | int localSize = Math.min(size, MAX_LOCAL_SIZE); 60 | return Range.create(size, localSize); 61 | } 62 | 63 | /** 64 | * Creates a two-dimensional range with the maximum local sizes. 65 | * 66 | * @param width Size of the first dimension. 67 | * @param height Size of the second dimension. 68 | * 69 | * @return The range. 70 | */ 71 | 72 | public static Range create2D(int width, int height) 73 | { 74 | assert (width == (width & -width)); // Must be a power of two 75 | assert (height == (height & -height)); // Must be a power of two 76 | int localWidth = Math.min(width, Util.sqrt4up(MAX_LOCAL_SIZE)), 77 | localHeight = Math.min(height, MAX_LOCAL_SIZE / localWidth); 78 | return Range.create2D(width, height, localWidth, localHeight); 79 | } 80 | 81 | /** 82 | * Maximum OpenCL work-group size. Note that this is the local sizes in all dimensions multiplied together. 83 | */ 84 | 85 | public static final int MAX_LOCAL_SIZE = 256; 86 | } 87 | -------------------------------------------------------------------------------- /apfloat/src/test/java/org/apfloat/ApfloatRuntimeExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2024 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import junit.framework.TestSuite; 27 | 28 | /** 29 | * @since 1.15.0 30 | * @version 1.15.0 31 | * @author Mikko Tommila 32 | */ 33 | 34 | public class ApfloatRuntimeExceptionTest 35 | extends ApfloatTestCase 36 | { 37 | public ApfloatRuntimeExceptionTest(String methodName) 38 | { 39 | super(methodName); 40 | } 41 | 42 | public static void main(String[] args) 43 | { 44 | junit.textui.TestRunner.run(suite()); 45 | } 46 | 47 | public static TestSuite suite() 48 | { 49 | TestSuite suite = new TestSuite(); 50 | 51 | suite.addTest(new ApfloatRuntimeExceptionTest("testLocalizedMessage")); 52 | suite.addTest(new ApfloatRuntimeExceptionTest("testLocalizedMessageWithArgs")); 53 | 54 | return suite; 55 | } 56 | 57 | public static void testLocalizedMessage() 58 | { 59 | ApfloatRuntimeException e = new ApfloatRuntimeException(null, "w.infinitePrecision"); 60 | assertEquals("Localization key", "w.infinitePrecision", e.getLocalizationKey()); 61 | assertEquals("Localization args length", 0, e.getLocalizationArgs().length); 62 | assertEquals("Localized message", "Cannot calculate W to infinite precision", e.getLocalizedMessage()); 63 | } 64 | 65 | public static void testLocalizedMessageWithArgs() 66 | { 67 | ApfloatRuntimeException e = new ApfloatRuntimeException(null, "maximumTransformLengthExceeded", 2, 1); 68 | assertEquals("Localization key", "maximumTransformLengthExceeded", e.getLocalizationKey()); 69 | assertEquals("Localization args length", 2, e.getLocalizationArgs().length); 70 | assertEquals("First localization arg", 2, e.getLocalizationArgs()[0]); 71 | assertEquals("Second localization arg", 1, e.getLocalizationArgs()[1]); 72 | assertEquals("Localized message", "Maximum transform length exceeded: 2 > 1", e.getLocalizedMessage()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /apfloat/src/test/java/org/apfloat/GCDHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat; 25 | 26 | import java.util.Random; 27 | 28 | import junit.framework.TestCase; 29 | import junit.framework.TestSuite; 30 | 31 | /** 32 | * @since 1.6 33 | * @version 1.6 34 | * @author Mikko Tommila 35 | */ 36 | 37 | public class GCDHelperTest 38 | extends TestCase 39 | { 40 | public GCDHelperTest(String methodName) 41 | { 42 | super(methodName); 43 | } 44 | 45 | public static void main(String[] args) 46 | { 47 | junit.textui.TestRunner.run(suite()); 48 | } 49 | 50 | public static TestSuite suite() 51 | { 52 | TestSuite suite = new TestSuite(); 53 | 54 | suite.addTest(new GCDHelperTest("testGcd")); 55 | 56 | return suite; 57 | } 58 | 59 | public static void testGcd() 60 | { 61 | Random random = new Random(); 62 | 63 | for (int i = 0; i < 5; i++) 64 | { 65 | Apint a = new Apint(getString(random)); 66 | Apint b = new Apint(getString(random)); 67 | 68 | Apint c = elementaryGcd(a, b); 69 | Apint d = ApintMath.gcd(a, b); 70 | 71 | assertEquals("GCD", c, d); 72 | } 73 | } 74 | 75 | private static String getString(Random random) 76 | { 77 | int length = random.nextInt(65000) + 35000; 78 | StringBuilder buffer = new StringBuilder(length); 79 | for (int i = 0; i < length; i++) 80 | { 81 | buffer.append((char) (random.nextInt(10) + (int) '0')); 82 | } 83 | 84 | return buffer.toString(); 85 | } 86 | 87 | private static Apint elementaryGcd(Apint a, Apint b) 88 | throws ApfloatRuntimeException 89 | { 90 | while (b.signum() != 0) 91 | { 92 | Apint r = a.mod(b); 93 | a = b; 94 | b = r; 95 | } 96 | 97 | return ApintMath.abs(a); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /apfloat/src/main/java/org/apfloat/spi/RadixConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.spi; 25 | 26 | /** 27 | * Constants related to different radixes. 28 | * 29 | * @version 1.0 30 | * @author Mikko Tommila 31 | */ 32 | 33 | public interface RadixConstants 34 | { 35 | /** 36 | * Factors of numbers 2, ..., 36. For 2 <= radix <= 36, 37 | * RADIX_FACTORS[radix] contains an array of 38 | * integers containing the different factors of the radix. 39 | */ 40 | 41 | public static final int RADIX_FACTORS[][] = { null, null, { 2 }, { 3 }, { 2 }, { 5 }, { 2, 3 }, { 7 }, { 2 }, { 3 }, { 2, 5 }, { 11 }, { 2, 3 }, { 13 }, { 2, 7 }, { 3, 5 }, { 2 }, { 17 }, { 2, 3 }, { 19 }, { 2, 5 }, { 3, 7 }, { 2, 11 }, { 23 }, { 2, 3 }, { 5 }, { 2, 13 }, { 3 }, { 2, 7 }, { 29 }, { 2, 3, 5 }, { 31 }, { 2 }, { 3, 11 }, { 2, 17 }, { 5, 7 }, { 2, 3 } }; 42 | 43 | /** 44 | * Precision of a float in the digits of each radix. 45 | */ 46 | 47 | public static final int FLOAT_PRECISION[] = { -1, -1, 24, 16, 12, 11, 10, 9, 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; 48 | 49 | /** 50 | * Precision of a double in the digits of each radix. 51 | */ 52 | 53 | public static final int DOUBLE_PRECISION[] = { -1, -1, 53, 34, 27, 23, 21, 19, 18, 17, 16, 16, 15, 15, 14, 14, 14, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11 }; 54 | 55 | /** 56 | * Precision of a long in the digits of each radix. 57 | */ 58 | 59 | public static final int LONG_PRECISION[] = { -1, -1, 63, 40, 32, 28, 25, 23, 21, 20, 19, 19, 18, 18, 17, 17, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13 }; 60 | 61 | /** 62 | * How many digits maximally fit in a long in each radix. 63 | */ 64 | 65 | public static final int LONG_DIGITS[] = { -1, -1, 63, 39, 31, 27, 24, 22, 21, 19, 18, 18, 17, 17, 16, 16, 15, 15, 15, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12 }; 66 | } 67 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeAdditionStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.ApfloatRuntimeException; 27 | import org.apfloat.spi.AdditionStrategy; 28 | import org.apfloat.spi.DataStorage.Iterator; 29 | 30 | /** 31 | * Basic addition strategy for the rawtype element type. 32 | * 33 | * @since 1.7.0 34 | * @version 1.7.0 35 | * @author Mikko Tommila 36 | */ 37 | public class RawtypeAdditionStrategy 38 | extends RawtypeBaseMath 39 | implements AdditionStrategy 40 | { 41 | /** 42 | * Creates an addition strategy using the specified radix. 43 | * 44 | * @param radix The radix that will be used. 45 | */ 46 | 47 | public RawtypeAdditionStrategy(int radix) 48 | { 49 | super(radix); 50 | } 51 | 52 | @Override 53 | public RawType add(Iterator src1, Iterator src2, RawType carry, Iterator dst, long size) 54 | throws ApfloatRuntimeException 55 | { 56 | return baseAdd(src1, src2, carry, dst, size); 57 | } 58 | 59 | @Override 60 | public RawType subtract(Iterator src1, Iterator src2, RawType carry, Iterator dst, long size) 61 | throws ApfloatRuntimeException 62 | { 63 | return baseSubtract(src1, src2, carry, dst, size); 64 | } 65 | 66 | @Override 67 | public RawType multiplyAdd(Iterator src1, Iterator src2, RawType src3, RawType carry, Iterator dst, long size) 68 | throws ApfloatRuntimeException 69 | { 70 | return baseMultiplyAdd(src1, src2, src3, carry, dst, size); 71 | } 72 | 73 | @Override 74 | public RawType divide(Iterator src1, RawType src2, RawType carry, Iterator dst, long size) 75 | throws ApfloatRuntimeException 76 | { 77 | return baseDivide(src1, src2, carry, dst, size); 78 | } 79 | 80 | @Override 81 | public RawType zero() 82 | { 83 | return (rawtype) 0; 84 | } 85 | 86 | private static final long serialVersionUID = ${org.apfloat.internal.RawtypeAdditionStrategy.serialVersionUID}; 87 | } 88 | -------------------------------------------------------------------------------- /apfloat/src/main/template/org/apfloat/internal/RawtypeConvolutionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.ConvolutionStrategy; 27 | import org.apfloat.spi.NTTStrategy; 28 | import static org.apfloat.internal.RawtypeConstants.*; 29 | 30 | /** 31 | * Creates convolutions of suitable type for the rawtype type.

32 | * 33 | * @see RawtypeShortConvolutionStrategy 34 | * @see RawtypeMediumConvolutionStrategy 35 | * @see RawtypeKaratsubaConvolutionStrategy 36 | * @see ThreeNTTConvolutionStrategy 37 | * 38 | * @version 1.7.0 39 | * @author Mikko Tommila 40 | */ 41 | 42 | public class RawtypeConvolutionBuilder 43 | extends AbstractConvolutionBuilder 44 | { 45 | /** 46 | * Default constructor. 47 | */ 48 | 49 | public RawtypeConvolutionBuilder() 50 | { 51 | } 52 | 53 | @Override 54 | protected int getKaratsubaCutoffPoint() 55 | { 56 | return RawtypeKaratsubaConvolutionStrategy.CUTOFF_POINT; 57 | } 58 | 59 | @Override 60 | protected float getKaratsubaCostFactor() 61 | { 62 | return KARATSUBA_COST_FACTOR; 63 | } 64 | 65 | @Override 66 | protected float getNTTCostFactor() 67 | { 68 | return NTT_COST_FACTOR; 69 | } 70 | 71 | @Override 72 | protected ConvolutionStrategy createShortConvolutionStrategy(int radix) 73 | { 74 | return new RawtypeShortConvolutionStrategy(radix); 75 | } 76 | 77 | @Override 78 | protected ConvolutionStrategy createMediumConvolutionStrategy(int radix) 79 | { 80 | return new RawtypeMediumConvolutionStrategy(radix); 81 | } 82 | 83 | @Override 84 | protected ConvolutionStrategy createKaratsubaConvolutionStrategy(int radix) 85 | { 86 | return new RawtypeKaratsubaConvolutionStrategy(radix); 87 | } 88 | 89 | @Override 90 | protected ConvolutionStrategy createThreeNTTConvolutionStrategy(int radix, NTTStrategy nttStrategy) 91 | { 92 | return new ParallelThreeNTTConvolutionStrategy(radix, nttStrategy); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /apfloat/src/test/template/org/apfloat/internal/RawtypeMediumConvolutionStrategyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2023 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.internal; 25 | 26 | import org.apfloat.spi.*; 27 | 28 | import junit.framework.TestSuite; 29 | 30 | /** 31 | * @version 1.0 32 | * @author Mikko Tommila 33 | */ 34 | 35 | public class RawtypeMediumConvolutionStrategyTest 36 | extends RawtypeConvolutionStrategyTestCase 37 | implements RawtypeRadixConstants 38 | { 39 | public RawtypeMediumConvolutionStrategyTest(String methodName) 40 | { 41 | super(methodName); 42 | } 43 | 44 | public static void main(String[] args) 45 | { 46 | junit.textui.TestRunner.run(suite()); 47 | } 48 | 49 | public static TestSuite suite() 50 | { 51 | TestSuite suite = new TestSuite(); 52 | 53 | suite.addTest(new RawtypeMediumConvolutionStrategyTest("testFull")); 54 | 55 | return suite; 56 | } 57 | 58 | public static void testFull() 59 | { 60 | for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) 61 | { 62 | rawtype b1 = BASE[radix] - (rawtype) 1; 63 | DataStorage src1 = createDataStorage(new rawtype[] { (rawtype) 1, (rawtype) 2, (rawtype) 3, (rawtype) 4 }), 64 | src2 = createDataStorage(new rawtype[] { (rawtype) 5, (rawtype) 6 }), 65 | src9 = createDataStorage(new rawtype[] { b1, b1, b1 }), 66 | src99 = createDataStorage(new rawtype[] { b1, b1, b1, b1, b1, b1 }); 67 | 68 | ConvolutionStrategy convolutionStrategy = new RawtypeMediumConvolutionStrategy(radix); 69 | 70 | DataStorage result = convolutionStrategy.convolute(src1, src2, 6); 71 | 72 | check("normal", radix, new rawtype[] { 0, (rawtype) 5, (rawtype) 16, (rawtype) 27, (rawtype) 38, (rawtype) 24 }, result); 73 | 74 | result = convolutionStrategy.convolute(src9, src99, 9); 75 | 76 | check("max", radix, new rawtype[] { b1, b1, b1 - (rawtype) 1, b1, b1, b1, 0, 0, (rawtype) 1 }, result); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /apfloat-aparapi/src/test/java/org/apfloat/aparapi/IntAparapiColumnSixStepFNTStrategyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2002-2025 Mikko Tommila 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.apfloat.aparapi; 25 | 26 | import org.apfloat.*; 27 | import org.apfloat.internal.*; 28 | 29 | import junit.framework.TestSuite; 30 | 31 | /** 32 | * @version 1.15.0 33 | * @author Mikko Tommila 34 | */ 35 | 36 | public class IntAparapiColumnSixStepFNTStrategyTest 37 | extends IntAparapiSixStepFNTStrategyTest 38 | { 39 | public IntAparapiColumnSixStepFNTStrategyTest(String methodName) 40 | { 41 | super(methodName); 42 | } 43 | 44 | public static void main(String[] args) 45 | { 46 | junit.textui.TestRunner.run(suite()); 47 | } 48 | 49 | public static TestSuite suite() 50 | { 51 | TestSuite suite = new TestSuite(); 52 | 53 | suite.addTest(new IntAparapiColumnSixStepFNTStrategyTest("testForward")); 54 | suite.addTest(new IntAparapiColumnSixStepFNTStrategyTest("testForwardBig")); 55 | suite.addTest(new IntAparapiColumnSixStepFNTStrategyTest("testRoundTrip")); 56 | suite.addTest(new IntAparapiColumnSixStepFNTStrategyTest("testRoundTripBig")); 57 | 58 | return suite; 59 | } 60 | 61 | public static void testForward() 62 | { 63 | runTestForward(1024); 64 | } 65 | 66 | public static void testForwardBig() 67 | { 68 | ApfloatContext ctx = ApfloatContext.getContext(); 69 | 70 | ctx.setMemoryThreshold(8192); 71 | runTestForward(4096); 72 | } 73 | 74 | private static void runTestForward(int size) 75 | { 76 | runTestForward(new IntAparapiColumnSixStepFNTStrategy(), size); 77 | } 78 | 79 | public static void testRoundTrip() 80 | { 81 | runRoundTrip(1024); 82 | } 83 | 84 | public static void testRoundTripBig() 85 | { 86 | int size = (int) Math.min(1 << 21, IntModConstants.MAX_TRANSFORM_LENGTH & -IntModConstants.MAX_TRANSFORM_LENGTH); 87 | runRoundTrip(size); 88 | } 89 | 90 | private static void runRoundTrip(int size) 91 | { 92 | runRoundTrip(new IntAparapiColumnSixStepFNTStrategy(), size); 93 | } 94 | } 95 | --------------------------------------------------------------------------------