Fix for I calculations

This commit is contained in:
Sergey Solovyev 2012-05-14 14:43:25 +04:00
parent 6c54cf8af0
commit f75bab4a01
6 changed files with 36 additions and 12 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="79" android:versionName="1.3.0" package="org.solovyev.android.calculator"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="79" android:versionName="1.2.34" package="org.solovyev.android.calculator">
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
@ -8,7 +8,7 @@
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/> <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
<application android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication"> <application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan"> <activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan">

View File

@ -64,7 +64,7 @@
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId> <artifactId>jscl</artifactId>
<version>0.0.1</version> <version>0.0.2</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>
@ -121,6 +121,12 @@
<!--<type>apklib</type>--> <!--<type>apklib</type>-->
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
</dependency>
<dependency> <dependency>
<groupId>com.intellij</groupId> <groupId>com.intellij</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>

View File

@ -6,14 +6,14 @@ import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog; import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
import org.solovyev.android.menu.ActivityMenuItem; import org.solovyev.android.menu.IdentifiableMenuItem;
/** /**
* User: serso * User: serso
* Date: 4/23/12 * Date: 4/23/12
* Time: 2:25 PM * Time: 2:25 PM
*/ */
enum CalculatorMenu implements ActivityMenuItem { enum CalculatorMenu implements IdentifiableMenuItem {
settings(R.id.main_menu_item_settings){ settings(R.id.main_menu_item_settings){
@Override @Override

View File

@ -114,7 +114,7 @@ public enum CalculatorEngine {
private final AndroidMathRegistry<Operator> postfixFunctionsRegistry = new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry()); private final AndroidMathRegistry<Operator> postfixFunctionsRegistry = new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry());
@NotNull @Nullable
private ThreadKiller threadKiller = new AndroidThreadKiller(); private ThreadKiller threadKiller = new AndroidThreadKiller();
// calculation thread timeout in seconds, after timeout thread would be interrupted // calculation thread timeout in seconds, after timeout thread would be interrupted
@ -256,8 +256,9 @@ public enum CalculatorEngine {
final Thread calculationThreadLocal = calculationThread.getObject(); final Thread calculationThreadLocal = calculationThread.getObject();
if (calculationThreadLocal != null) { if (calculationThreadLocal != null) {
// todo serso: interrupt doesn't stop the thread but it MUST be killed if (threadKiller != null) {
threadKiller.killThread(calculationThreadLocal); threadKiller.killThread(calculationThreadLocal);
}
//calculationThreadLocal.stop(); //calculationThreadLocal.stop();
} }
@ -396,7 +397,7 @@ public enum CalculatorEngine {
} }
// for tests only // for tests only
void setThreadKiller(@NotNull ThreadKiller threadKiller) { void setThreadKiller(@Nullable ThreadKiller threadKiller) {
this.threadKiller = threadKiller; this.threadKiller = threadKiller;
} }

View File

@ -6,6 +6,8 @@
package org.solovyev.android.calculator.jscl; package org.solovyev.android.calculator.jscl;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.math.Expression; import jscl.math.Expression;
import jscl.math.Generic; import jscl.math.Generic;
import org.junit.Assert; import org.junit.Assert;
@ -29,8 +31,18 @@ public class FromJsclNumericTextProcessorTest {
public void testCreateResultForComplexNumber() throws Exception { public void testCreateResultForComplexNumber() throws Exception {
final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor(); final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor();
final JsclMathEngine me = JsclMathEngine.instance;
final AngleUnit defaultAngleUnits = me.getAngleUnits();
Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric())); Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric()));
Assert.assertEquals("1.22133+1.2i", cm.process(Expression.valueOf("1.22133232+1.2*i").numeric())); Assert.assertEquals("1.22133+1.2i", cm.process(Expression.valueOf("1.22133232+1.2*i").numeric()));
Assert.assertEquals("1.22133+0i", cm.process(Expression.valueOf("1.22133232+0.000000001*i").numeric()));
try {
me.setAngleUnits(AngleUnit.rad);
Assert.assertEquals("1-0i", cm.process(Expression.valueOf("-(e^(i*π))").numeric()));
} finally {
me.setAngleUnits(defaultAngleUnits);
}
Assert.assertEquals("1.22i", cm.process(Expression.valueOf("1.22*i").numeric())); Assert.assertEquals("1.22i", cm.process(Expression.valueOf("1.22*i").numeric()));
Assert.assertEquals("i", cm.process(Expression.valueOf("i").numeric())); Assert.assertEquals("i", cm.process(Expression.valueOf("i").numeric()));
Generic numeric = Expression.valueOf("e^(Π*i)+1").numeric(); Generic numeric = Expression.valueOf("e^(Π*i)+1").numeric();

View File

@ -18,7 +18,6 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<android.sdk.path>/home/ssolovyev/projects/org.solovyev/misc/lib/android-sdk-linux_x86</android.sdk.path>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -56,6 +55,12 @@
<version>2.3.1</version> <version>2.3.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>