|
| 1 | +/* |
| 2 | + * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. |
| 3 | + * Copyright (C) 2018-2024 Tilman Neumann - [email protected] |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License |
| 6 | + * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. |
| 7 | + * |
| 8 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 9 | + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 10 | + * |
| 11 | + * You should have received a copy of the GNU General Public License along with this program; |
| 12 | + * if not, see <http://www.gnu.org/licenses/>. |
| 13 | + */ |
| 14 | +package de.tilman_neumann.jml.roots; |
| 15 | + |
| 16 | +import java.io.BufferedReader; |
| 17 | +import java.io.InputStreamReader; |
| 18 | +import java.math.BigDecimal; |
| 19 | + |
| 20 | +import org.apache.logging.log4j.Logger; |
| 21 | +import org.apache.logging.log4j.LogManager; |
| 22 | + |
| 23 | +import de.tilman_neumann.jml.precision.Scale; |
| 24 | +import de.tilman_neumann.util.ConfigUtil; |
| 25 | +import de.tilman_neumann.util.TimeUtil; |
| 26 | + |
| 27 | +/** |
| 28 | + * Test i.th root of floating point numbers by user input. |
| 29 | + * |
| 30 | + * @author Tilman Neumann |
| 31 | + */ |
| 32 | +public class RootsRealRunner { |
| 33 | + private static final Logger LOG = LogManager.getLogger(RootsRealRunner.class); |
| 34 | + |
| 35 | + /** |
| 36 | + * Test. |
| 37 | + * @param argv command line arguments |
| 38 | + */ |
| 39 | + public static void main(String[] argv) { |
| 40 | + ConfigUtil.initProject(); |
| 41 | + |
| 42 | + while (true) { |
| 43 | + try { |
| 44 | + LOG.info("\nPlease insert <x> <maximal scale>:"); |
| 45 | + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
| 46 | + String line = in.readLine(); |
| 47 | + String[] splitted = line.split("\\s+"); |
| 48 | + BigDecimal x = new BigDecimal(splitted[0]); |
| 49 | + Integer maxScaleInput = Integer.parseInt(splitted[1]); |
| 50 | + Scale maxScale = Scale.valueOf(maxScaleInput); |
| 51 | + long t0, t1; |
| 52 | + |
| 53 | + t0 = System.currentTimeMillis(); |
| 54 | + for (int i=2; i<10; i++) { |
| 55 | + for (Scale scale = Scale.valueOf(2); scale.compareTo(maxScale)<=0; scale = scale.add(1)) { |
| 56 | + LOG.debug(i + ".th root(" + x + ", " + scale + ")=" + RootsReal.ithRoot(x, i, scale)); |
| 57 | + } |
| 58 | + } |
| 59 | + t1 = System.currentTimeMillis(); |
| 60 | + LOG.debug("Time of root computations: " + TimeUtil.timeDiffStr(t0,t1)); |
| 61 | + } catch (Exception ex) { |
| 62 | + LOG.error("Error " + ex, ex); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments