Skip to content

Commit 0b03f9c

Browse files
committed
Merge branch 'add_option_scientificnotation' into dev. Add in question level option "scientificnotation".
2 parents a24246b + 2e41605 commit 0b03f9c

22 files changed

+165
-9
lines changed

api/config_sample.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ $CFG->logicsymbol = 'lang';
8080
$CFG->inversetrig = 'cos-1';
8181
$CFG->matrixparens = "[";
8282
$CFG->decimals = ".";
83+
$CFG->scientificnotation = "*10";
8384

8485
$CFG->inputtype = 'algebraic';
8586
$CFG->inputboxsize = 30;

api/util/StackQuestionLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public static function loadxml($xml) {
149149
'decimals',
150150
isset($xmldata->question->decimals) ? (string) $xmldata->question->decimals : get_config('qtype_stack', 'decimals')
151151
);
152+
$question->options->set_option(
153+
'scientificnotation',
154+
isset($xmldata->question->scientificnotation) ? (string) $xmldata->question->scientificnotation : get_config('qtype_stack', 'scientificnotation')
155+
);
152156

153157
$inputmap = [];
154158
foreach ($xmldata->question->input as $input) {

backup/moodle2/backup_qtype_stack_plugin.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ protected function define_question_plugin_structure() {
4949
'stackversion', 'questionvariables', 'specificfeedback', 'specificfeedbackformat',
5050
'questionnote', 'questionsimplify', 'assumepositive', 'assumereal',
5151
'prtcorrect', 'prtcorrectformat', 'prtpartiallycorrect', 'prtpartiallycorrectformat',
52-
'prtincorrect', 'prtincorrectformat', 'decimals', 'multiplicationsign', 'sqrtsign',
52+
'prtincorrect', 'prtincorrectformat',
53+
'decimals',
54+
'scientificnotation',
55+
'multiplicationsign', 'sqrtsign',
5356
'complexno', 'inversetrig', 'logicsymbol', 'matrixparens', 'variantsselectionseed',
5457
]);
5558

db/install.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<FIELD NAME="prtincorrect" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Standard feedback displayed for any PRT that returns a score of 0."/>
2727
<FIELD NAME="prtincorrectformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Text format for the prtincorrect field."/>
2828
<FIELD NAME="decimals" TYPE="char" LENGTH="8" NOTNULL="true" DEFAULT="." SEQUENCE="false" COMMENT="The symbol to use for the decimal separator."/>
29+
<FIELD NAME="scientificnotation" TYPE="char" LENGTH="8" NOTNULL="true" DEFAULT="*10" SEQUENCE="false" COMMENT="Controls display of numbers written in scientific notation."/>
2930
<FIELD NAME="multiplicationsign" TYPE="char" LENGTH="8" NOTNULL="true" DEFAULT="dot" SEQUENCE="false" COMMENT="The symbol to use for multiplication."/>
3031
<FIELD NAME="sqrtsign" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Whether to display square roots as surds."/>
3132
<FIELD NAME="complexno" TYPE="char" LENGTH="8" NOTNULL="true" DEFAULT="i" SEQUENCE="false" COMMENT="How complex numbers should be displayed and represented."/>

db/upgrade.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ function xmldb_qtype_stack_upgrade($oldversion) {
938938
$table = new xmldb_table('qtype_stack_options');
939939
$field = new xmldb_field('decimals', XMLDB_TYPE_CHAR, '8', null, XMLDB_NOTNULL, null, '.');
940940

941-
// Conditionally launch add field variantsselectionseed.
941+
// Conditionally launch add field decimals.
942942
if (!$dbman->field_exists($table, $field)) {
943943
$dbman->add_field($table, $field);
944944
}
@@ -961,6 +961,18 @@ function xmldb_qtype_stack_upgrade($oldversion) {
961961
upgrade_plugin_savepoint(true, 2024032401, 'qtype', 'stack');
962962
}
963963

964+
if ($oldversion < 2024043000) {
965+
$table = new xmldb_table('qtype_stack_options');
966+
$field = new xmldb_field('scientificnotation', XMLDB_TYPE_CHAR, '8', null, XMLDB_NOTNULL, null, '*10');
967+
968+
// Conditionally launch add field scientificnotation.
969+
if (!$dbman->field_exists($table, $field)) {
970+
$dbman->add_field($table, $field);
971+
}
972+
973+
// STACK savepoint reached.
974+
upgrade_plugin_savepoint(true, 2024043000, 'qtype', 'stack');
975+
}
964976
// Add new upgrade blocks just above here.
965977

966978
// Check the version of the Maxima library code that comes with this version

doc/en/Authoring/Options.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ The design of this option is discussed further in the [developer docs](../Develo
4747

4848
Teachers must always use strict Maxima syntax, which requires `.`, including in test case construction.
4949

50+
### Scientific notation formal {#scientificnotation} ###
51+
52+
Choose the format for display of scientific notation.
53+
54+
* '*10', numbers will be displayed as \(3.14 \times 10^{3}\).
55+
* 'E', numbers will be displayed as \(3.14 E^{3}\).
56+
5057
### Multiplication Sign {#multiplication} ###
5158

5259
* (none), e.g. \(x(x+1)\)

doc/en/Developer/Development_track.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ past development history is documented on [Development history](Development_hist
55

66
## Version 4.6.0
77

8-
TODO: merge back in https://github.com/maths/moodle-qtype_stack/tree/add_option_scientificnotation once the code tidy is confirmed.
9-
108
This version will require moodle 4.0+. Moodle 3.x is no longer supported.
119

1210
1. Alter list of acceptible expressions. Unicode super/subscripts now are invalid. Use 150_replace filter in students' input.
@@ -15,7 +13,7 @@ This version will require moodle 4.0+. Moodle 3.x is no longer supported.
1513
4. Fix display and simplification of binomial coefficients (issue #931).
1614
5. Add in the `CT:...` and `RAW:...` options for test case construction to enable tests of invalid input (e.g. missing stars).
1715
6. STACK now has an [API](../Installation/API.md) to provide STACK questions as a web service.
18-
7. Improve the display of floats. Numbers of decimal places are now respected in all parts of expressions, and floats such as `1.7E-9` are displayed at \(1.7 \times 10^{-9}\).
16+
7. Improve the display of floats. Numbers of decimal places are now respected in all parts of expressions, and floats such as `1.7E-9` are displayed at \(1.7 \times 10^{-9}\). There is a new question option to choose between \(1.7 \times 10^{-9}\) and \(1.7E-9\).
1917
8. Release first version of the API for longer term support, and better support for ILIAS.
2018

2119
TODO:

doc/en/Developer/Extracting_test_questions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ echo "',<br>
110110
'itemid' => 0,<br>
111111
];<br>
112112
\$formform->decimals = '{$fromform->decimals}';<br>
113+
\$formform->scientificnotation = '{$fromform->scientificnotation}';<br>
113114
\$formform->multiplicationsign = '{$fromform->multiplicationsign}';<br>
114115
\$formform->sqrtsign = '{$fromform->sqrtsign}';<br>
115116
\$formform->complexno = '{$fromform->complexno}';<br>
@@ -224,6 +225,7 @@ echo "<br>
224225
));<br>";
225226
}
226227
echo "\$q->options->set_option('decimals', '{$fromform->decimals}');<br>
228+
\$q->options->set_option('scientificnotation', '{$fromform->scientificnotation}');<br>
227229
\$q->options->set_option('multiplicationsign', '{$fromform->multiplicationsign}');<br>
228230
\$q->options->set_option('complexno', '{$fromform->complexno}');<br>
229231
\$q->options->set_option('inversetrig', '{$fromform->inversetrig}');<br>

edit_stack_form.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ protected function definition_inner(/* MoodleQuickForm */ $mform) {
320320
$mform->setDefault('decimals', $this->stackconfig->decimals);
321321
$mform->addHelpButton('decimals', 'decimals', 'qtype_stack');
322322

323+
$mform->addElement('select', 'scientificnotation',
324+
stack_string('scientificnotation'), stack_options::get_scientificnotation_options());
325+
$mform->setDefault('scientificnotation', $this->stackconfig->scientificnotation);
326+
$mform->addHelpButton('scientificnotation', 'scientificnotation', 'qtype_stack');
327+
323328
$mform->addElement('select', 'multiplicationsign',
324329
stack_string('multiplicationsign'), stack_options::get_multiplication_sign_options());
325330
$mform->setDefault('multiplicationsign', $this->stackconfig->multiplicationsign);
@@ -716,6 +721,7 @@ protected function data_preprocessing_options($question) {
716721
$question->prtincorrect = $this->prepare_text_field('prtincorrect',
717722
$opt->prtincorrect, $opt->prtincorrectformat, $question->id);
718723
$question->decimals = $opt->decimals;
724+
$question->scientificnotation = $opt->scientificnotation;
719725
$question->multiplicationsign = $opt->multiplicationsign;
720726
$question->complexno = $opt->complexno;
721727
$question->inversetrig = $opt->inversetrig;

lang/en/qtype_stack.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@
221221
$string['decimals'] = 'Decimal separator';
222222
$string['decimals_help'] = 'Choose the symbol, and options, for the decimal separator.';
223223
$string['decimals_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Options.md#decimals';
224+
$string['scientificnotation'] = 'Scientific notation';
225+
$string['scientificnotation_help'] = 'Choose the format of scientific notation.';
226+
$string['scientificnotation_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Options.md#scientificnotation';
227+
$string['scientificnotation_10'] = 'n * 10^m';
228+
$string['scientificnotation_E'] = 'n E m';
224229
$string['multcross'] = 'Cross';
225230
$string['multdot'] = 'Dot';
226231
$string['multonlynumbers'] = 'Only numbers';

questiontype.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public function save_question_options($fromform) {
163163
$context, 'qtype_stack', 'prtincorrect', $fromform->id);
164164
$options->prtincorrectformat = $fromform->prtincorrect['format'];
165165
$options->decimals = $fromform->decimals;
166+
$options->scientificnotation = $fromform->scientificnotation;
166167
$options->multiplicationsign = $fromform->multiplicationsign;
167168
$options->sqrtsign = $fromform->sqrtsign;
168169
$options->complexno = $fromform->complexno;
@@ -477,6 +478,7 @@ protected function initialise_question_instance(question_definition $question, $
477478

478479
$question->options = new stack_options();
479480
$question->options->set_option('decimals', $questiondata->options->decimals);
481+
$question->options->set_option('scientificnotation', $questiondata->options->scientificnotation);
480482
$question->options->set_option('multiplicationsign', $questiondata->options->multiplicationsign);
481483
$question->options->set_option('complexno', $questiondata->options->complexno);
482484
$question->options->set_option('inversetrig', $questiondata->options->inversetrig);
@@ -1243,6 +1245,7 @@ public function export_to_xml($questiondata, qformat_xml $format, $notused = nul
12431245
$output .= $this->export_xml_text($format, 'prtincorrect', $options->prtincorrect,
12441246
$options->prtincorrectformat, $contextid, 'prtincorrect', $questiondata->id);
12451247
$output .= " <decimals>{$options->decimals}</decimals>\n";
1248+
$output .= " <scientificnotation>{$options->scientificnotation}</scientificnotation>\n";
12461249
$output .= " <multiplicationsign>{$options->multiplicationsign}</multiplicationsign>\n";
12471250
$output .= " <sqrtsign>{$options->sqrtsign}</sqrtsign>\n";
12481251
$output .= " <complexno>{$options->complexno}</complexno>\n";
@@ -1391,6 +1394,7 @@ public function import_from_xml($xml, $fromform, qformat_xml $format, $notused =
13911394
$fromform->prtincorrect = $this->import_xml_text($xml, 'prtincorrect', $format, $fformat);
13921395
$fromform->penalty = $format->getpath($xml, ['#', 'penalty', 0, '#'], 0.1);
13931396
$fromform->decimals = $format->getpath($xml, ['#', 'decimals', 0, '#'], '.');
1397+
$fromform->scientificnotation = $format->getpath($xml, ['#', 'scientificnotation', 0, '#'], 'dot');
13941398
$fromform->multiplicationsign = $format->getpath($xml, ['#', 'multiplicationsign', 0, '#'], 'dot');
13951399
$fromform->sqrtsign = $format->getpath($xml, ['#', 'sqrtsign', 0, '#'], 1);
13961400
$fromform->complexno = $format->getpath($xml, ['#', 'complexno', 0, '#'], 'i');
@@ -1593,6 +1597,7 @@ public function validate_fromform($fromform, $errors) {
15931597

15941598
$this->options = new stack_options();
15951599
$this->options->set_option('decimals', $fromform['decimals']);
1600+
$this->options->set_option('scientificnotation', $fromform['scientificnotation']);
15961601
$this->options->set_option('multiplicationsign', $fromform['multiplicationsign']);
15971602
$this->options->set_option('complexno', $fromform['complexno']);
15981603
$this->options->set_option('inversetrig', $fromform['inversetrig']);

settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@
253253
get_string('decimals_help', 'qtype_stack'), '.',
254254
stack_options::get_decimals_sign_options()));
255255

256+
$settings->add(new admin_setting_configselect('qtype_stack/scientificnotation',
257+
get_string('scientificnotation', 'qtype_stack'),
258+
get_string('scientificnotation_help', 'qtype_stack'), '*10',
259+
stack_options::get_scientificnotation_options()));
260+
256261
$settings->add(new admin_setting_configselect('qtype_stack/multiplicationsign',
257262
get_string('multiplicationsign', 'qtype_stack'),
258263
get_string('multiplicationsign_help', 'qtype_stack'), 'dot',

stack/cas/security-map.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7757,6 +7757,10 @@
77577757
"function": "t",
77587758
"contextvariable": "true"
77597759
},
7760+
"texput_scientificnotation": {
7761+
"function": "t",
7762+
"contextvariable": "true"
7763+
},
77607764
"texsub": {
77617765
"function": "s",
77627766
"built-in": true

stack/maxima/assessment.mac

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,23 @@ displayscitex(ex):=block([ss, n, dp, tx],
832832
),
833833
tx
834834
)$
835-
texput(displaysci, displayscitex)$
835+
836+
displayscitexE(ex):=block([ss, n, dp, tx],
837+
[n, dp, expo]:args(ex),
838+
ss:sconcat("~,", string(dp), "fE{~a}"),
839+
if is(equal(dp, 0)) then ss:"~dE{~a}",
840+
tx:ev(printf(false, ss, ev(float(n)), expo), simp),
841+
if is(stackfltsep = ",") then (
842+
tx:ssubst("\\ ", ",", tx),
843+
tx:ssubst("{,}", ".", tx)
844+
),
845+
tx
846+
)$
847+
848+
texput_scientificnotation(ex) := block(
849+
if is(ex="*10") then texput(displaysci, displayscitex),
850+
if is(ex="E") then texput(displaysci, displayscitexE)
851+
)$
836852

837853
make_displayscivalue(ex):= block([n, d, expo, ss],
838854
if atom(ex) then return(ex),

stack/maxima/stackmaxima.mac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3334,4 +3334,4 @@ is_lang(code):=ev(is(%_STACK_LANG=code),simp=true)$
33343334

33353335
/* Stack expects some output with the version number the output happens at */
33363336
/* maximalocal.mac after additional library loading */
3337-
stackmaximaversion:2024042200$
3337+
stackmaximaversion:2024043000$

stack/options.class.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public function __construct($settings = []) {
4545
'caskey' => 'texput_decimal',
4646
'castype' => 'fun',
4747
],
48+
'scientificnotation' => [
49+
'type' => 'list',
50+
'value' => '*10',
51+
'strict' => true,
52+
'values' => array('*10', 'E'),
53+
'caskey' => 'texput_scientificnotation',
54+
'castype' => 'fun',
55+
],
4856
'multiplicationsign' => [
4957
'type' => 'list',
5058
'value' => 'dot',
@@ -137,6 +145,7 @@ public function set_site_defaults() {
137145
$stackconfig = stack_utils::get_config();
138146
// Display option does not match up to $stackconfig->mathsdisplay).
139147
$this->set_option('decimals', $stackconfig->decimals);
148+
$this->set_option('scientificnotation', $stackconfig->scientificnotation);
140149
$this->set_option('multiplicationsign', $stackconfig->multiplicationsign);
141150
$this->set_option('complexno', $stackconfig->complexno);
142151
$this->set_option('inversetrig', $stackconfig->inversetrig);
@@ -264,6 +273,16 @@ public static function get_decimals_sign_options() {
264273
];
265274
}
266275

276+
/**
277+
* @return array of choices for the scientific notation select menu.
278+
*/
279+
public static function get_scientificnotation_options() {
280+
return array(
281+
'*10' => get_string('scientificnotation_10', 'qtype_stack'),
282+
'E' => get_string('scientificnotation_E', 'qtype_stack'),
283+
);
284+
}
285+
267286
/**
268287
* @return array of choices for the multiplication sign select menu.
269288
*/

tests/api_stackquestionloader_test.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function test_question_loader_use_defaults() {
6868
$ql = new StackQuestionLoader();
6969
$question = $ql->loadXML($xml);
7070
$this->assertEquals($question->options->get_option('decimals'), get_config('qtype_stack', 'decimals'));
71+
$this->assertEquals($question->options->get_option('scientificnotation'),
72+
get_config('qtype_stack', 'scientificnotation'));
7173
$this->assertEquals($question->options->get_option('assumepos'), get_config('qtype_stack', 'assumepositive'));
7274
$this->assertEquals($question->options->get_option('assumereal'), get_config('qtype_stack', 'assumereal'));
7375
$this->assertEquals($question->options->get_option('multiplicationsign'), get_config('qtype_stack', 'multiplicationsign'));
@@ -97,6 +99,7 @@ public function test_question_loader_do_not_use_defaults() {
9799
$ql = new StackQuestionLoader();
98100
$question = $ql->loadXML($xml);
99101
$this->assertEquals($question->options->get_option('decimals'), ',');
102+
$this->assertEquals($question->options->get_option('scientificnotation'), '*10');
100103
$this->assertEquals($question->options->get_option('assumepos'), true);
101104
$this->assertEquals($question->options->get_option('assumereal'), true);
102105
$this->assertEquals($question->options->get_option('multiplicationsign'), 'cross');

tests/fixtures/apifixtures.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ class stack_api_test_data {
415415
<assumepositive>1</assumepositive>
416416
<assumereal>1</assumereal>
417417
<decimals>,</decimals>
418+
<scientificnotation>*10</scientificnotation>
418419
<multiplicationsign>cross</multiplicationsign>
419420
<sqrtsign>0</sqrtsign>
420421
<complexno>j</complexno>
@@ -1272,6 +1273,7 @@ class stack_api_test_data {
12721273
<text><![CDATA[<span style="font-size: 1.5em; color:red;"><i class="fa fa-times"></i></span> Incorrect answer.]]></text>
12731274
</prtincorrect>
12741275
<decimals>.</decimals>
1276+
<scientificnotation>*10</scientificnotation>
12751277
<multiplicationsign>dot</multiplicationsign>
12761278
<sqrtsign>1</sqrtsign>
12771279
<complexno>i</complexno>

0 commit comments

Comments
 (0)