Skip to content

Commit

Permalink
"to"-conversion for physical constants
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-kn committed Apr 10, 2018
1 parent ec3fdb4 commit 7b6c825
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2018-04-09 Hanna Knutsson <hanna.knutsson@protonmail.com>

* "to"-conversion for physical constants

2018-04-08 Hanna Knutsson <hanna.knutsson@protonmail.com>

* Support for "handle vector" argument property

2018-04-03 Hanna Knutsson <hanna.knutsson@protonmail.com>

* Time zone conversion
Expand Down
4 changes: 4 additions & 0 deletions doc/C/qalculate-gtk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,10 @@ Putting <quote> to </quote> followed by an expression at the end of the mathemat
<listitem><para>Convert to units (e.g. km/h).</para></listitem>
</varlistentry>
<varlistentry>
<term>A physical constant</term>
<listitem><para>Convert to variable as unit (e.g. c).</para></listitem>
</varlistentry>
<varlistentry>
<term>base</term>
<listitem><para>Convert to base units.</para></listitem>
</varlistentry>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/html/qalculate-definitions-variables.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/html/qalculate-expressions.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
If the limit implicit multiplication option is activated, the use of implicit multiplication when parsing expressions and displaying results will be limited to avoid confusion. For example, if this mode is not activated and <span class="quote"><span class="quote">integrte(5x)</span></span> is accidently typed instead of <span class="quote"><span class="quote">integrate(5x)</span></span>, the expression is interpreted as <span class="quote"><span class="quote">int(e * e * (5 * x) * gr * t)</span></span> (displayed in history window). The result will then without any error be <span class="quote"><span class="quote">int(2.3940139x * km^2)</span></span> instead of <span class="quote"><span class="quote">2.5x^2</span></span>. If limit implicit multiplication is activated, the mistyped expression would instead show an error telling that <span class="quote"><span class="quote">integrte</span></span> is not a valid variable, function or unit (unless unknowns is enabled in which case the result will be <span class="quote"><span class="quote">5 "integrate" * x</span></span>). When implicit multiplication is limited, variables, functions and units must be separated by a space, operator or parenthesis (<span class="quote"><span class="quote">xy</span></span> does not equal <span class="quote"><span class="quote">x * y</span></span>).
</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="qalculate-to"></a>The <span class="quote"><span class="quote">to</span></span> operator</h2></div></div></div><p>
Putting <span class="quote"><span class="quote"> to </span></span> followed by an expression at the end of the mathematical expression is mainly used for unit conversion (see <a class="xref" href="qalculate-units.html#qalculate-unit-conversion" title="Conversion">the section called “Conversion”</a>). There are however also some convenient commands that can be typed after <span class="quote"><span class="quote"> to </span></span>. Here is a list of possible <span class="quote"><span class="quote">to</span></span> values:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">A unit</span></dt><dd><p>Convert to unit (e.g. meter, prepend with ? to request the optimal prefix).</p></dd><dt><span class="term">A unit expression</span></dt><dd><p>Convert to units (e.g. km/h).</p></dd><dt><span class="term">base</span></dt><dd><p>Convert to base units.</p></dd><dt><span class="term">optimal</span></dt><dd><p>Convert to optimal unit.</p></dd><dt><span class="term">mixed</span></dt><dd><p>Convert to mixed units (e.g. 5 ft + 8 in).</p></dd><dt><span class="term">bin / binary</span></dt><dd><p>Show as binary number.</p></dd><dt><span class="term">oct / octal</span></dt><dd><p>Show as octal number.</p></dd><dt><span class="term">hex / hexadecimal</span></dt><dd><p>Show as hexadecimal number.</p></dd><dt><span class="term">bases</span></dt><dd><p>Show as binary, octal, decimal and hexadecimal number (opens convert bases dialog with the mathematical expression).</p></dd><dt><span class="term">fraction</span></dt><dd><p>Show as number in combined fractional format.</p></dd><dt><span class="term">factors</span></dt><dd><p>Show factorized (algebraic or integer factorization).</p></dd><dt><span class="term">utc</span></dt><dd><p>Show date and time using UTC time zone.</p></dd></dl></div><p>
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">A unit</span></dt><dd><p>Convert to unit (e.g. meter, prepend with ? to request the optimal prefix).</p></dd><dt><span class="term">A unit expression</span></dt><dd><p>Convert to units (e.g. km/h).</p></dd><dt><span class="term">A physical constant</span></dt><dd><p>Convert to variable as unit (e.g. c).</p></dd><dt><span class="term">base</span></dt><dd><p>Convert to base units.</p></dd><dt><span class="term">optimal</span></dt><dd><p>Convert to optimal unit.</p></dd><dt><span class="term">mixed</span></dt><dd><p>Convert to mixed units (e.g. 5 ft + 8 in).</p></dd><dt><span class="term">bin / binary</span></dt><dd><p>Show as binary number.</p></dd><dt><span class="term">oct / octal</span></dt><dd><p>Show as octal number.</p></dd><dt><span class="term">hex / hexadecimal</span></dt><dd><p>Show as hexadecimal number.</p></dd><dt><span class="term">bases</span></dt><dd><p>Show as binary, octal, decimal and hexadecimal number (opens convert bases dialog with the mathematical expression).</p></dd><dt><span class="term">fraction</span></dt><dd><p>Show as number in combined fractional format.</p></dd><dt><span class="term">factors</span></dt><dd><p>Show factorized (algebraic or integer factorization).</p></dd><dt><span class="term">utc</span></dt><dd><p>Show date and time using UTC time zone.</p></dd></dl></div><p>
</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="qalculate-user-interface.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="qalculate-mode.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. User Interface </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 4. Calculator Modes</td></tr></table></div></body></html>
26 changes: 16 additions & 10 deletions src/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1359,14 +1359,21 @@ void display_parse_status() {
parsed_expression += _("factors");
} else if(equalsIgnoreCase(str_u, "utc") || equalsIgnoreCase(str_u, "gmt")) {
parsed_expression += _("UTC time zone");
} else {
CALCULATOR->beginTemporaryStopMessages();
CompositeUnit cu("", "temporary_composite_parse", "", str_u);
int warnings_count;
had_errors = CALCULATOR->endTemporaryStopMessages(NULL, &warnings_count) > 0 || had_errors;
had_warnings = had_warnings || warnings_count > 0;
mparse = cu.generateMathStructure(!printops.negative_exponents);
mparse.format(po);
} else {
Variable *v = CALCULATOR->getVariable(str_u);
if(v && (!v->isKnown() || ((KnownVariable*) v)->unit().empty())) v = NULL;
if(v && CALCULATOR->getUnit(str_u)) v = NULL;
if(v) {
mparse = v;
} else {
CALCULATOR->beginTemporaryStopMessages();
CompositeUnit cu("", "temporary_composite_parse", "", str_u);
int warnings_count;
had_errors = CALCULATOR->endTemporaryStopMessages(NULL, &warnings_count) > 0 || had_errors;
had_warnings = had_warnings || warnings_count > 0;
mparse = cu.generateMathStructure(!printops.negative_exponents);
mparse.format(po);
}
parsed_expression += mparse.print(po);
}
}
Expand Down Expand Up @@ -9704,7 +9711,6 @@ void edit_dataset(DataSet *ds, GtkWidget *win) {
gchar *gstr = gtk_text_buffer_get_text(copyright_buffer, &c_iter_s, &c_iter_e, FALSE);
ds->setCopyright(gstr);
g_free(gstr);
DataPropertyIter it;
for(size_t i = 0; i < tmp_props.size();) {
if(!tmp_props[i]) {
if(tmp_props_orig[i]) ds->delProperty(tmp_props_orig[i]);
Expand Down Expand Up @@ -13356,7 +13362,7 @@ void do_completion() {
bool b_match = false;
if(item) {
if((editing_to_expression || !evalops.parse_options.functions_enabled) && item->type() == TYPE_FUNCTION) {}
else if((editing_to_expression || !evalops.parse_options.variables_enabled) && item->type() == TYPE_VARIABLE) {}
else if(item->type() == TYPE_VARIABLE && (!evalops.parse_options.variables_enabled || (editing_to_expression && (!((Variable*) item)->isKnown() || ((KnownVariable*) item)->unit().empty())))) {}
else if(!evalops.parse_options.units_enabled && item->type() == TYPE_UNIT) {}
else {
for(size_t name_i = 1; name_i <= item->countNames() && !b_match; name_i++) {
Expand Down

0 comments on commit 7b6c825

Please sign in to comment.