A lot of performance improvements

This commit is contained in:
Andrea Cavalli 2017-09-15 23:24:12 +02:00
parent 70adfc81b6
commit 30512b143d
27 changed files with 226 additions and 31 deletions

View File

@ -6,7 +6,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>

1
.gitignore vendored
View File

@ -10,6 +10,7 @@
/target/ /target/
/backups/ /backups/
/Resources_and_Videos/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*

View File

@ -1,6 +1,14 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

Binary file not shown.

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui; package org.warp.picalculator.gui;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Semaphore;
import org.warp.picalculator.Main; import org.warp.picalculator.Main;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
@ -234,6 +235,13 @@ public final class DisplayManager implements RenderingLoop {
} }
private void draw_init() { private void draw_init() {
if (engine.supportsFontRegistering()) {
for (BinaryFont f : engine.getRegisteredFonts()) {
if (!f.isInitialized()) {
f.initialize(engine);
}
}
}
renderer.glClear(engine.getWidth(), engine.getHeight()); renderer.glClear(engine.getWidth(), engine.getHeight());
} }
@ -375,11 +383,12 @@ public final class DisplayManager implements RenderingLoop {
public void loop() { public void loop() {
try { try {
load_skin();
load_fonts();
engine.create(); engine.create();
renderer = engine.getRenderer(); renderer = engine.getRenderer();
load_skin();
load_fonts();
try { try {
screen.initialize(); screen.initialize();
} catch (final Exception e) { } catch (final Exception e) {

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui.graphicengine; package org.warp.picalculator.gui.graphicengine;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
public interface GraphicEngine { public interface GraphicEngine {
@ -16,6 +17,8 @@ public interface GraphicEngine {
public void create(); public void create();
public void create(Runnable object);
public boolean wasResized(); public boolean wasResized();
public int getWidth(); public int getWidth();
@ -39,4 +42,8 @@ public interface GraphicEngine {
public boolean isSupported(); public boolean isSupported();
public boolean doesRefreshPauses(); public boolean doesRefreshPauses();
public boolean supportsFontRegistering();
public ArrayList<BinaryFont> getRegisteredFonts();
} }

View File

@ -8,5 +8,7 @@ public interface Skin {
public void initialize(GraphicEngine d); public void initialize(GraphicEngine d);
public boolean isInitialized();
public void use(GraphicEngine d); public void use(GraphicEngine d);
} }

View File

@ -4,6 +4,7 @@ import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException; import javax.swing.UnsupportedLookAndFeelException;
@ -48,11 +49,18 @@ public class CPUEngine implements GraphicEngine {
@Override @Override
public void create() { public void create() {
create(null);
}
@Override
public void create(Runnable onInitialized) {
INSTANCE = new SwingWindow(this); INSTANCE = new SwingWindow(this);
setResizable(Utils.debugOn & !Utils.debugThirdScreen); setResizable(Utils.debugOn & !Utils.debugThirdScreen);
setDisplayMode(Main.screenSize[0], Main.screenSize[1]); setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
INSTANCE.setVisible(true); INSTANCE.setVisible(true);
initialized = true; initialized = true;
if (onInitialized != null)
onInitialized.run();
} }
@Override @Override
@ -185,4 +193,16 @@ public class CPUEngine implements GraphicEngine {
public boolean doesRefreshPauses() { public boolean doesRefreshPauses() {
return true; return true;
} }
@Override
public boolean supportsFontRegistering() {
// TODO Auto-generated method stub
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -149,8 +149,6 @@ public class CPUFont implements BinaryFont {
@Override @Override
public void initialize(GraphicEngine d) { public void initialize(GraphicEngine d) {
// TODO Auto-generated method stub
} }
@Override @Override
@ -178,4 +176,9 @@ public class CPUFont implements BinaryFont {
return charH; return charH;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -48,4 +48,9 @@ public class CPUSkin implements Skin {
((CPURenderer) d.getRenderer()).currentSkin = this; ((CPURenderer) d.getRenderer()).currentSkin = this;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -1,10 +1,12 @@
package org.warp.picalculator.gui.graphicengine.gpu; package org.warp.picalculator.gui.graphicengine.gpu;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import org.warp.picalculator.Main; import org.warp.picalculator.Main;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.Skin; import org.warp.picalculator.gui.graphicengine.Skin;
@ -18,6 +20,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
private RenderingLoop d; private RenderingLoop d;
private GPURenderer r; private GPURenderer r;
int[] size = new int[] { Main.screenSize[0], Main.screenSize[1] }; int[] size = new int[] { Main.screenSize[0], Main.screenSize[1] };
private final ArrayList<BinaryFont> registeredFonts = new ArrayList<BinaryFont>();
@Override @Override
public int[] getSize() { public int[] getSize() {
@ -53,6 +56,11 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
@Override @Override
public void create() { public void create() {
create(null);
}
@Override
public void create(Runnable onInitialized) {
created = true; created = true;
r = new GPURenderer(); r = new GPURenderer();
wnd = new NEWTWindow(this); wnd = new NEWTWindow(this);
@ -60,6 +68,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
setDisplayMode(Main.screenSize[0], Main.screenSize[1]); setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
setResizable(Utils.debugOn & !Utils.debugThirdScreen); setResizable(Utils.debugOn & !Utils.debugThirdScreen);
initialized = true; initialized = true;
wnd.onInitialized = onInitialized;
} }
@Override @Override
@ -104,12 +113,12 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
@Override @Override
public BinaryFont loadFont(String file) throws IOException { public BinaryFont loadFont(String file) throws IOException {
return new GPUFont(file); return new GPUFont(this, file);
} }
@Override @Override
public Skin loadSkin(String file) throws IOException { public Skin loadSkin(String file) throws IOException {
return new GPUSkin(file); return new GPUSkin(this, file);
} }
@Override @Override
@ -146,4 +155,18 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
return false; return false;
} }
public void registerFont(GPUFont gpuFont) {
registeredFonts.add(gpuFont);
}
@Override
public boolean supportsFontRegistering() {
return true;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
return registeredFonts;
}
} }

View File

@ -25,10 +25,11 @@ public class GPUFont implements BinaryFont {
public int memoryWidthOfEachColumn; public int memoryWidthOfEachColumn;
private boolean initialized = false; private boolean initialized = false;
private CPUFont tmpFont; private BufferedImage tmpFont;
GPUFont(String file) throws IOException { GPUFont(GraphicEngine g, String file) throws IOException {
load(file); load(file);
((GPUEngine) g).registerFont(this);
} }
@Override @Override
@ -38,7 +39,7 @@ public class GPUFont implements BinaryFont {
charH = font.charH; charH = font.charH;
minCharIndex = font.minBound; minCharIndex = font.minBound;
maxCharIndex = font.maxBound; maxCharIndex = font.maxBound;
tmpFont = font; pregenTexture(font.rawchars);
font = null; font = null;
} }
@ -56,7 +57,7 @@ public class GPUFont implements BinaryFont {
return (ch & 0xFFFF) - minCharIndex; return (ch & 0xFFFF) - minCharIndex;
} }
private void genTexture(boolean[][] chars) { private void pregenTexture(boolean[][] chars) {
final double totalChars = maxCharIndex - minCharIndex; final double totalChars = maxCharIndex - minCharIndex;
final int w = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charW))); final int w = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charW)));
final int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH))); final int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH)));
@ -86,11 +87,17 @@ public class GPUFont implements BinaryFont {
memoryWidth = w; memoryWidth = w;
memoryHeight = h; memoryHeight = h;
memoryWidthOfEachColumn = maxIndexW; memoryWidthOfEachColumn = maxIndexW;
texture = GPURenderer.importTexture(bfi);
textureW = bfi.getWidth(); textureW = bfi.getWidth();
textureH = bfi.getHeight(); textureH = bfi.getHeight();
bfi.flush(); this.tmpFont = bfi;
bfi = null; } catch (GLException e) {
e.printStackTrace();
}
}
private void genTexture() {
try {
texture = GPURenderer.importTexture(tmpFont);
} catch (GLException | IOException e) { } catch (GLException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -102,9 +109,7 @@ public class GPUFont implements BinaryFont {
@Override @Override
public void initialize(GraphicEngine d) { public void initialize(GraphicEngine d) {
genTexture(tmpFont.rawchars); genTexture();
tmpFont.chars32 = null;
tmpFont.rawchars = null;
tmpFont = null; tmpFont = null;
initialized = true; initialized = true;
} }
@ -138,4 +143,9 @@ public class GPUFont implements BinaryFont {
public int getCharacterHeight() { public int getCharacterHeight() {
return charH; return charH;
} }
@Override
public boolean isInitialized() {
return initialized;
}
} }

View File

@ -3,6 +3,7 @@ package org.warp.picalculator.gui.graphicengine.gpu;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;

View File

@ -20,7 +20,7 @@ public class GPUSkin implements Skin {
private String texturePath; private String texturePath;
private boolean initialized = false; private boolean initialized = false;
GPUSkin(String file) throws IOException { GPUSkin(GraphicEngine d, String file) throws IOException {
load(file); load(file);
} }
@ -57,4 +57,9 @@ public class GPUSkin implements Skin {
r.useTexture(t, w, h); r.useTexture(t, w, h);
} }
@Override
public boolean isInitialized() {
return initialized;
}
} }

View File

@ -60,6 +60,7 @@ class NEWTWindow implements GLEventListener {
private final GPUEngine disp; private final GPUEngine disp;
private final GPURenderer renderer; private final GPURenderer renderer;
public Runnable onInitialized;
public NEWTWindow(GPUEngine disp) { public NEWTWindow(GPUEngine disp) {
this.disp = disp; this.disp = disp;
@ -291,6 +292,10 @@ class NEWTWindow implements GLEventListener {
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glShadeModel(GLLightingFunc.GL_FLAT); gl.glShadeModel(GLLightingFunc.GL_FLAT);
if (onInitialized != null) {
onInitialized.run();
onInitialized = null;
}
try { try {
renderer.currentTex = ((GPUSkin) disp.loadSkin("test.png")).t; renderer.currentTex = ((GPUSkin) disp.loadSkin("test.png")).t;
} catch (final Exception e) { } catch (final Exception e) {

View File

@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.AnsiConsole;
@ -16,6 +17,7 @@ import org.warp.picalculator.Main;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.gui.graphicengine.RenderingLoop;
@ -64,6 +66,11 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
@Override @Override
public void create() { public void create() {
this.create(null);
}
@Override
public void create(Runnable onInitialized) {
Utils.outputLevel = -1; Utils.outputLevel = -1;
AnsiConsole.systemInstall(); AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){ if(Utils.isWindows() && !Utils.msDosMode){
@ -134,6 +141,8 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
t.start(); t.start();
} }
stopped = false; stopped = false;
if (onInitialized != null)
onInitialized.run();
} }
@Override @Override
@ -321,4 +330,14 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
public boolean doesRefreshPauses() { public boolean doesRefreshPauses() {
return true; return true;
} }
@Override
public boolean supportsFontRegistering() {
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
return null;
}
} }

View File

@ -39,4 +39,9 @@ public class Headless24bitFont implements BinaryFont {
return 5; return 5;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -57,5 +57,10 @@ public class Headless24bitSkin implements Skin {
((Headless24bitRenderer) d.getRenderer()).currentSkin = this; ((Headless24bitRenderer) d.getRenderer()).currentSkin = this;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui.graphicengine.headless256; package org.warp.picalculator.gui.graphicengine.headless256;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.AnsiConsole;
@ -9,6 +10,7 @@ import org.warp.picalculator.Main;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer; import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
@ -56,6 +58,11 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
@Override @Override
public void create() { public void create() {
this.create(null);
}
@Override
public void create(Runnable onInitialized) {
Utils.outputLevel = -1; Utils.outputLevel = -1;
AnsiConsole.systemInstall(); AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){ if(Utils.isWindows() && !Utils.msDosMode){
@ -126,6 +133,8 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
t.start(); t.start();
} }
stopped = false; stopped = false;
if (onInitialized != null)
onInitialized.run();
} }
@Override @Override
@ -271,4 +280,16 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
public boolean doesRefreshPauses() { public boolean doesRefreshPauses() {
return true; return true;
} }
@Override
public boolean supportsFontRegistering() {
// TODO Auto-generated method stub
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -39,4 +39,9 @@ public class Headless256Font implements BinaryFont {
return 5; return 5;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -61,5 +61,10 @@ public class Headless256Skin implements Skin {
((Headless256Renderer) d.getRenderer()).currentSkin = this; ((Headless256Renderer) d.getRenderer()).currentSkin = this;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.gui.graphicengine.headless8; package org.warp.picalculator.gui.graphicengine.headless8;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.AnsiConsole;
@ -9,6 +10,8 @@ import org.warp.picalculator.Main;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer; import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
@ -56,6 +59,11 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
@Override @Override
public void create() { public void create() {
this.create(null);
}
@Override
public void create(Runnable onInitialized) {
Utils.outputLevel = -1; Utils.outputLevel = -1;
AnsiConsole.systemInstall(); AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){ if(Utils.isWindows() && !Utils.msDosMode){
@ -126,6 +134,8 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
t.start(); t.start();
} }
stopped = false; stopped = false;
if (onInitialized != null)
onInitialized.run();
} }
@Override @Override
@ -271,4 +281,16 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
public boolean doesRefreshPauses() { public boolean doesRefreshPauses() {
return true; return true;
} }
@Override
public boolean supportsFontRegistering() {
// TODO Auto-generated method stub
return false;
}
@Override
public ArrayList<BinaryFont> getRegisteredFonts() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -39,4 +39,9 @@ public class Headless8Font implements BinaryFont {
return 5; return 5;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -56,5 +56,10 @@ public class Headless8Skin implements Skin {
((Headless8Renderer) d.getRenderer()).currentSkin = this; ((Headless8Renderer) d.getRenderer()).currentSkin = this;
} }
@Override
public boolean isInitialized() {
return true;
}
} }

View File

@ -60,7 +60,8 @@ public class Division extends FunctionOperator {
if (((Number) variable1).isInteger() && ((Number) variable2).isInteger()) { if (((Number) variable1).isInteger() && ((Number) variable2).isInteger()) {
LinkedList<BigInteger> factors1 = ((Number) variable1).getFactors(); LinkedList<BigInteger> factors1 = ((Number) variable1).getFactors();
LinkedList<BigInteger> factors2 = ((Number) variable2).getFactors(); LinkedList<BigInteger> factors2 = ((Number) variable2).getFactors();
return factors1.retainAll(factors2) /* True If something changed in the factors list by keeping only the intersection of the two factor lists */ && factors1.size() > 0 /* true if there is at least one common factor */; factors1.retainAll(factors2);
return factors1.size() > 0 /* true if there is at least one common factor */;
} else if (((Number) variable1).divide((Number) variable2).isInteger()) { } else if (((Number) variable1).divide((Number) variable2).isInteger()) {
return true; return true;
} else { } else {
@ -99,15 +100,14 @@ public class Division extends FunctionOperator {
if (getMathContext().exactMode && (((Number) variable1).isInteger() && ((Number) variable2).isInteger())) { if (getMathContext().exactMode && (((Number) variable1).isInteger() && ((Number) variable2).isInteger())) {
LinkedList<BigInteger> factors1 = ((Number) variable1).getFactors(); LinkedList<BigInteger> factors1 = ((Number) variable1).getFactors();
LinkedList<BigInteger> factors2 = ((Number) variable2).getFactors(); LinkedList<BigInteger> factors2 = ((Number) variable2).getFactors();
if(factors1.retainAll(factors2)) { //True If something changed in the factors list by keeping only the intersection of the two factor lists. factors1.retainAll(factors2);
BigInteger nmb1 = ((Number) this.getParameter1()).term.toBigIntegerExact(); BigInteger nmb1 = ((Number) this.getParameter1()).term.toBigIntegerExact();
BigInteger nmb2 = ((Number) this.getParameter2()).term.toBigIntegerExact(); BigInteger nmb2 = ((Number) this.getParameter2()).term.toBigIntegerExact();
for (BigInteger i : factors1) { for (BigInteger i : factors1) {
nmb1 = nmb1.divide(i); nmb1 = nmb1.divide(i);
nmb2 = nmb2.divide(i); nmb2 = nmb2.divide(i);
}
result.add(new Division(mathContext, new Number(mathContext, nmb1), new Number(mathContext, nmb2)));
} }
result.add(new Division(mathContext, new Number(mathContext, nmb1), new Number(mathContext, nmb2)));
} else { } else {
result.add(((Number) variable1).divide((Number) variable2)); result.add(((Number) variable1).divide((Number) variable2));
} }

View File

@ -75,10 +75,13 @@ public class Number implements Function {
public Number pow(Number f) throws Error { public Number pow(Number f) throws Error {
Number ret = new Number(root, BigDecimal.ONE); Number ret = new Number(root, BigDecimal.ONE);
if (Utils.isIntegerValue(f.term)) { if (Utils.isIntegerValue(f.term)) {
final BigInteger bi = f.term.toBigInteger(); final BigInteger bi = f.term.toBigInteger().abs();
for (BigInteger i = BigInteger.ZERO; i.compareTo(bi) < 0; i = i.add(BigInteger.ONE)) { for (BigInteger i = BigInteger.ZERO; i.compareTo(bi) < 0; i = i.add(BigInteger.ONE)) {
ret = ret.multiply(new Number(root, getTerm())); ret = ret.multiply(new Number(root, getTerm()));
} }
if (f.term.signum() == -1) {
ret = new Number(root, 1).divide(ret);
}
} else { } else {
ret.term = BigDecimalMath.pow(term, f.term); ret.term = BigDecimalMath.pow(term, f.term);
} }

1
src/main/resources/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/Thumbs.db