├── 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 |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 |
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 |24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/site/resources/applet/signedpiparallel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/site/resources/applet/pi.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/site/resources/applet/signedpi.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |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 |15 | 16 | Calculator help 17 | 18 |
28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/site/resources/applet/signedcalculator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |15 | 16 | Calculator help 17 | 18 |
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
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
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
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
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
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
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
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
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
31 | *
32 | * @since 1.7.0
33 | * @version 1.7.0
34 | * @author Mikko Tommila
35 | */
36 |
37 | public class RawtypeAdditionBuilder
38 | implements AdditionBuilder
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
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
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
41 | *
42 | * While this method may functionally appear to be equivalent to just
43 | * calling
48 | *
49 | * The purpose of this method is to allow keeping all threads of the
50 | *
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
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 |
42 | *
43 | * For maximum performance,
57 | *
58 | * For maximum performance,
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 |
--------------------------------------------------------------------------------
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.long element type using column orientation.int element type using column orientation.int element type using row orientation.long element type using column orientation.long element type using row orientation.int element type using row orientation.long element type using row orientation.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.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 ShutdownMaprawtype type.
33 | *
34 | * @since 1.7.0
35 | * @version 1.7.0
36 | * @author Mikko Tommila
37 | */
38 |
39 | public class RawtypeCarryCRTBuilder
40 | implements CarryCRTBuilderint 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.long element type.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 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.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.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.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
33 | *
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 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 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.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).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).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 ConcurrentSoftHashMapRADIX_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 AdditionStrategyrawtype type.