scientific notation format
This commit is contained in:
parent
b7f7e82634
commit
8b23c532da
@ -20,6 +20,7 @@
|
||||
<string name="c_prefs_main_category">Основные настройки</string>
|
||||
<string name="c_prefs_calculations_category">Настройки вычислений</string>
|
||||
<string name="c_prefs_appearance_category">Настройки внешнего вида</string>
|
||||
<string name="c_prefs_other_category">Другие настройки</string>
|
||||
<string name="c_prefs_drag_button_category">Настройки кнопок</string>
|
||||
|
||||
|
||||
@ -41,6 +42,8 @@
|
||||
<string name="c_calc_color_display_title">Подсветка выражений</string>
|
||||
<string name="c_calc_round_result_title">Округление результата</string>
|
||||
<string name="c_calc_round_result_summary">Включает/выключает округление результата</string>
|
||||
<string name="c_calc_science_notation_title">Результат в научной форме</string>
|
||||
<string name="c_calc_science_notation_summary">Если включено - результат будет всегда записан в научной форме (12.34E-12)</string>
|
||||
<string name="p_calc_result_precision_title">Точность результата</string>
|
||||
<string name="c_exit">Выход</string>
|
||||
<string name="c_add">Добавить</string>
|
||||
|
@ -33,6 +33,9 @@
|
||||
<string name="p_calc_round_result_key">org.solovyev.android.calculator.CalculatorModel_round_result</string>
|
||||
<string name="p_calc_round_result">true</string>
|
||||
|
||||
<string name="p_calc_science_notation_key">calculation.output.science_notation</string>
|
||||
<string name="p_calc_science_notation">false</string>
|
||||
|
||||
<string name="p_calc_functions">org.solovyev.android.calculator.CalculatorModel_functions</string>
|
||||
<string name="p_calc_vars">org.solovyev.android.calculator.CalculatorModel_vars</string>
|
||||
<string name="p_calc_history">org.solovyev.android.calculator.CalculatorModel_history</string>
|
||||
|
@ -20,6 +20,7 @@
|
||||
<string name="c_prefs_main_category">Main settings</string>
|
||||
<string name="c_prefs_calculations_category">Calculation settings</string>
|
||||
<string name="c_prefs_appearance_category">Appearance settings</string>
|
||||
<string name="c_prefs_other_category">Other settings</string>
|
||||
<string name="c_prefs_drag_button_category">Drag buttons settings</string>
|
||||
|
||||
|
||||
@ -41,6 +42,8 @@
|
||||
<string name="c_calc_color_display_title">Highlight expressions</string>
|
||||
<string name="c_calc_round_result_title">Round result</string>
|
||||
<string name="c_calc_round_result_summary">Toggles rounding of the result</string>
|
||||
<string name="c_calc_science_notation_title">Always scientific notation</string>
|
||||
<string name="c_calc_science_notation_summary">If turned on forces to use only scientific notation of output (12.34E-12)</string>
|
||||
<string name="p_calc_result_precision_title">Precision of result</string>
|
||||
<string name="c_exit">Exit</string>
|
||||
<string name="c_add">Add</string>
|
||||
|
@ -10,12 +10,12 @@
|
||||
a:defaultValue="false"
|
||||
/>
|
||||
|
||||
<PreferenceCategory a:title="@string/c_prefs_calculations_category">
|
||||
|
||||
<org.solovyev.android.ads.AdViewPreference
|
||||
a:key="admob_01"
|
||||
a:layout="@layout/admob_pref"/>
|
||||
|
||||
<PreferenceScreen a:title="@string/c_prefs_calculations_category">
|
||||
|
||||
<android.preference.CheckBoxPreference
|
||||
a:key="@string/p_calc_round_result_key"
|
||||
a:summary="@string/c_calc_round_result_summary"
|
||||
@ -29,18 +29,18 @@
|
||||
a:defaultValue="5"
|
||||
range:boundaries="0;16"/>
|
||||
|
||||
<android.preference.CheckBoxPreference
|
||||
a:key="@string/p_calc_science_notation_key"
|
||||
a:summary="@string/c_calc_science_notation_summary"
|
||||
a:title="@string/c_calc_science_notation_title"
|
||||
a:defaultValue="false"/>
|
||||
|
||||
<ListPreference a:key="@string/p_calc_grouping_separator_key"
|
||||
a:title="@string/c_calc_grouping_separator"
|
||||
a:entries="@array/p_grouping_separator_names"
|
||||
a:summary="@string/c_calc_grouping_separator_summary"
|
||||
a:entryValues="@array/p_grouping_separator_values"/>
|
||||
|
||||
<ListPreference a:key="@string/p_calc_multiplication_sign_key"
|
||||
a:title="@string/c_calc_multiplication_sign"
|
||||
a:entries="@array/p_multiplication_sign_values"
|
||||
a:summary="@string/c_calc_multiplication_sign_summary"
|
||||
a:entryValues="@array/p_multiplication_sign_values"/>
|
||||
|
||||
<ListPreference a:key="@string/p_calc_angle_units_key"
|
||||
a:title="@string/c_calc_angle_units"
|
||||
a:entries="@array/p_angle_units_names"
|
||||
@ -53,14 +53,10 @@
|
||||
a:summary="@string/c_numeral_bases_summary"
|
||||
a:entryValues="@array/p_numeral_bases"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
|
||||
<PreferenceCategory a:title="@string/c_prefs_appearance_category">
|
||||
|
||||
<org.solovyev.android.ads.AdViewPreference
|
||||
a:key="admob_02"
|
||||
a:layout="@layout/admob_pref"/>
|
||||
<PreferenceScreen
|
||||
a:title="@string/c_prefs_appearance_category">
|
||||
|
||||
<android.preference.CheckBoxPreference
|
||||
a:key="@string/p_calc_color_display_key"
|
||||
@ -80,6 +76,12 @@
|
||||
a:summary="@string/p_calc_haptic_feedback_duration_summary"
|
||||
a:entryValues="@array/p_calc_haptic_feedback_duration_values"/>
|
||||
|
||||
<ListPreference a:key="@string/p_calc_multiplication_sign_key"
|
||||
a:title="@string/c_calc_multiplication_sign"
|
||||
a:entries="@array/p_multiplication_sign_values"
|
||||
a:summary="@string/c_calc_multiplication_sign_summary"
|
||||
a:entryValues="@array/p_multiplication_sign_values"/>
|
||||
|
||||
<ListPreference a:key="@string/p_calc_theme_key"
|
||||
a:title="@string/c_calc_theme"
|
||||
a:entries="@array/p_theme_names"
|
||||
@ -102,19 +104,7 @@
|
||||
range:steps="10"
|
||||
range:boundaries="10;500"/>
|
||||
|
||||
<android.preference.CheckBoxPreference
|
||||
a:key="@string/p_calc_show_release_notes_key"
|
||||
a:summary="@string/c_calc_show_release_notes_summary"
|
||||
a:title="@string/c_calc_show_release_notes_title"
|
||||
a:defaultValue="true"/>
|
||||
|
||||
<android.preference.CheckBoxPreference
|
||||
a:key="@string/p_calc_use_back_button_as_prev_key"
|
||||
a:summary="@string/c_calc_use_back_button_as_prev_summary"
|
||||
a:title="@string/c_calc_use_back_button_as_prev_title"
|
||||
a:defaultValue="false"/>
|
||||
|
||||
<!-- <org.solovyev.android.prefs.FloatRangeSeekBarPreference
|
||||
<!-- <org.solovyev.android.prefs.FloatRangeSeekBarPreference
|
||||
a:key="@string/p_drag_duration_key"
|
||||
a:title="Duration of drag event"
|
||||
a:text=" ms"
|
||||
@ -129,6 +119,23 @@
|
||||
a:defaultValue="0;45"
|
||||
range:steps="5"
|
||||
range:boundaries="0;45"/>-->
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
a:title="@string/c_prefs_other_category">
|
||||
|
||||
<android.preference.CheckBoxPreference
|
||||
a:key="@string/p_calc_show_release_notes_key"
|
||||
a:summary="@string/c_calc_show_release_notes_summary"
|
||||
a:title="@string/c_calc_show_release_notes_title"
|
||||
a:defaultValue="true"/>
|
||||
|
||||
<android.preference.CheckBoxPreference
|
||||
a:key="@string/p_calc_use_back_button_as_prev_key"
|
||||
a:summary="@string/c_calc_use_back_button_as_prev_summary"
|
||||
a:title="@string/c_calc_use_back_button_as_prev_title"
|
||||
a:defaultValue="false"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
</PreferenceScreen>
|
@ -47,6 +47,9 @@ public enum CalculatorEngine {
|
||||
private static final String MULTIPLICATION_SIGN_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_multiplication_sign";
|
||||
private static final String MULTIPLICATION_SIGN_DEFAULT = "×";
|
||||
|
||||
private static final String SCIENCE_NOTATION_P_KEY = "calculation.output.science_notation";
|
||||
private static final boolean SCIENCE_NOTATION_DEFAULT = false;
|
||||
|
||||
private static final String ROUND_RESULT_P_KEY = "org.solovyev.android.calculator.CalculatorModel_round_result";
|
||||
private static final boolean ROUND_RESULT_DEFAULT = true;
|
||||
|
||||
@ -66,8 +69,10 @@ public enum CalculatorEngine {
|
||||
public static final Preference<Boolean> roundResult = new BooleanPreference(ROUND_RESULT_P_KEY, ROUND_RESULT_DEFAULT);
|
||||
public static final Preference<NumeralBase> numeralBase = StringPreference.newInstance(NUMERAL_BASES_P_KEY, NUMERAL_BASES_DEFAULT, EnumMapper.newInstance(NumeralBase.class));
|
||||
public static final Preference<AngleUnit> angleUnit = StringPreference.newInstance(ANGLE_UNITS_P_KEY, ANGLE_UNITS_DEFAULT, EnumMapper.newInstance(AngleUnit.class));
|
||||
public static final Preference<Boolean> scienceNotation = new BooleanPreference(SCIENCE_NOTATION_P_KEY, SCIENCE_NOTATION_DEFAULT);
|
||||
|
||||
private static final List<String> preferenceKeys = new ArrayList<String>();
|
||||
|
||||
static {
|
||||
preferenceKeys.add(groupingSeparator.getKey());
|
||||
preferenceKeys.add(multiplicationSign.getKey());
|
||||
@ -75,6 +80,7 @@ public enum CalculatorEngine {
|
||||
preferenceKeys.add(roundResult.getKey());
|
||||
preferenceKeys.add(numeralBase.getKey());
|
||||
preferenceKeys.add(angleUnit.getKey());
|
||||
preferenceKeys.add(scienceNotation.getKey());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -255,7 +261,7 @@ public enum CalculatorEngine {
|
||||
|
||||
if (parseExceptionObject != null || evalExceptionObject != null) {
|
||||
if (operation == JsclOperation.numeric &&
|
||||
( preparedExpression.isExistsUndefinedVar() || ( evalExceptionObject != null && evalExceptionObject.getCause() instanceof NumeralBaseException)) ) {
|
||||
(preparedExpression.isExistsUndefinedVar() || (evalExceptionObject != null && evalExceptionObject.getCause() instanceof NumeralBaseException))) {
|
||||
return evaluate(JsclOperation.simplify, expression, mr);
|
||||
}
|
||||
|
||||
@ -296,21 +302,7 @@ public enum CalculatorEngine {
|
||||
|
||||
public void reset(@Nullable Context context, @Nullable SharedPreferences preferences) {
|
||||
synchronized (lock) {
|
||||
if (preferences != null) {
|
||||
this.setPrecision(Preferences.precision.getPreference(preferences));
|
||||
this.setRoundResult(Preferences.roundResult.getPreference(preferences));
|
||||
this.setAngleUnits(getAngleUnitsFromPrefs(preferences));
|
||||
this.setNumeralBase(getNumeralBaseFromPrefs(preferences));
|
||||
this.setMultiplicationSign(Preferences.multiplicationSign.getPreference(preferences));
|
||||
|
||||
final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences);
|
||||
if (StringUtils.isEmpty(groupingSeparator)) {
|
||||
this.getEngine().setUseGroupingSeparator(false);
|
||||
} else {
|
||||
this.getEngine().setUseGroupingSeparator(true);
|
||||
this.getEngine().setGroupingSeparator(groupingSeparator.charAt(0));
|
||||
}
|
||||
}
|
||||
softReset(context, preferences);
|
||||
|
||||
varsRegistry.load(context, preferences);
|
||||
functionsRegistry.load(context, preferences);
|
||||
@ -327,6 +319,7 @@ public enum CalculatorEngine {
|
||||
this.setAngleUnits(getAngleUnitsFromPrefs(preferences));
|
||||
this.setNumeralBase(getNumeralBaseFromPrefs(preferences));
|
||||
this.setMultiplicationSign(Preferences.multiplicationSign.getPreference(preferences));
|
||||
this.setScienceNotation(Preferences.scienceNotation.getPreference(preferences));
|
||||
|
||||
final String groupingSeparator = Preferences.groupingSeparator.getPreference(preferences);
|
||||
if (StringUtils.isEmpty(groupingSeparator)) {
|
||||
@ -391,6 +384,10 @@ public enum CalculatorEngine {
|
||||
getEngine().setAngleUnits(angleUnits);
|
||||
}
|
||||
|
||||
public void setScienceNotation(boolean scienceNotation) {
|
||||
getEngine().setScienceNotation(scienceNotation);
|
||||
}
|
||||
|
||||
public void setNumeralBase(@NotNull NumeralBase numeralBase) {
|
||||
getEngine().setNumeralBase(numeralBase);
|
||||
}
|
||||
|
@ -261,6 +261,14 @@ public class CalculatorEngineTest {
|
||||
Assert.assertEquals("∫((ln(2)+ln(5))/ln(x), x)", cm.getEngine().simplify("∫(log(x, 10), x)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatting() throws Exception {
|
||||
final CalculatorEngine ce = CalculatorEngine.instance;
|
||||
|
||||
Assert.assertEquals("12 345", ce.evaluate(JsclOperation.simplify, "12345").getResult());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testI() throws CalculatorParseException, CalculatorEvalException {
|
||||
final CalculatorEngine cm = CalculatorEngine.instance;
|
||||
|
Loading…
Reference in New Issue
Block a user