Add command for pi

Add a command for pi. This inserts itself in equations for the moment.
Until we have a setting for numerical approximations, we will remain
with a symbolic value.

Fixes: #143

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2023-07-18 12:56:34 +02:00
parent cf8a51baa4
commit aac1bf89f5
8 changed files with 28 additions and 11 deletions

View file

@ -7,7 +7,7 @@ extern const unsigned char EditorFont_sparse_font_data[];
const unsigned char EditorFont_sparse_font_data[73997] FONT_QSPI =
{
0xF3, 0x01, 0x88, 0xC2, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0xF4, 0x01, 0x88, 0xC2, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x20, 0x5F, 0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x02, 0x0B,
0x05, 0x21, 0x09, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7,
0x1E, 0x00, 0x00, 0xB8, 0xFF, 0xFF, 0xFF, 0x0E, 0x03, 0x0B, 0x0B, 0x0F, 0x11, 0x8F, 0x7F, 0xFC,

View file

@ -7,7 +7,7 @@ extern const unsigned char HelpFont_sparse_font_data[];
const unsigned char HelpFont_sparse_font_data[15078] FONT_QSPI =
{
0xF3, 0x01, 0xE2, 0x75, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00,
0xF4, 0x01, 0xE2, 0x75, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00,
0x11, 0x01, 0x01, 0x03, 0x00, 0x20, 0x5F, 0x00, 0x11, 0x01, 0x01, 0x03, 0x00, 0x01, 0x04, 0x02,
0x0D, 0x04, 0xFF, 0xFF, 0xF3, 0x03, 0x01, 0x04, 0x04, 0x05, 0x06, 0xFF, 0xFF, 0x0F, 0x01, 0x04,
0x08, 0x0D, 0x0A, 0x12, 0x12, 0x14, 0x7F, 0x7F, 0x24, 0x24, 0x24, 0xFE, 0xFE, 0x28, 0x48, 0x48,

View file

@ -7,7 +7,7 @@ extern const unsigned char StackFont_sparse_font_data[];
const unsigned char StackFont_sparse_font_data[36570] FONT_QSPI =
{
0xF3, 0x01, 0xD5, 0x9D, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0xF4, 0x01, 0xD5, 0x9D, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x20, 0x5F, 0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x02, 0x05,
0x03, 0x17, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xC0, 0xFF, 0x1F, 0x02, 0x05, 0x08, 0x0A,
0x0C, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0x01, 0x05, 0x0E, 0x17, 0x10,

View file

@ -408,3 +408,14 @@ COMMAND_BODY(Version)
return OK;
return ERROR;
}
COMMAND_BODY(pi)
// ----------------------------------------------------------------------------
// Push the value of π on the stack
// ----------------------------------------------------------------------------
{
if (!rt.push(command::static_object(ID_pi)))
return ERROR;
return OK;
}

View file

@ -150,6 +150,6 @@ COMMAND_DECLARE(SystemSetup); // Select the system menu
COMMAND_DECLARE(HomeDirectory); // Return the home directory
COMMAND_DECLARE(Version); // Return a version string
COMMAND_DECLARE(ToList); // Build a list from stack
COMMAND_DECLARE(pi); // The value of 4 * atan(1)
#endif // COMMAND_H

View file

@ -113,6 +113,7 @@ ID(decimal128)
#define LAST_DECIMAL_TYPE ID_decimal128
#define LAST_REAL_TYPE ID_decimal128
ID(local)
ID(symbol)
ID(equation)
@ -141,7 +142,13 @@ CMD(False)
NAMED(ToText, "→Text")
ALIAS(ToText, "→Str")
#define FIRST_ALGEBRAIC ID_add
#define FIRST_ALGEBRAIC ID_pi
#define FIRST_SYMBOLIC_CONSTANT ID_pi
NAMED(pi, "π")
NAMED(ImaginaryUnit, "")
#define LAST_SYMBOLIC_CONSTANT ID_ImaginaryUnit
OP(add, "+")
OP(sub, "-")
OP(mul, "×")
@ -224,9 +231,7 @@ CMD(im)
CMD(arg)
CMD(conj)
NAMED(ImaginaryUnit, "")
#define LAST_ALGEBRAIC ID_ImaginaryUnit
#define LAST_ALGEBRAIC ID_conj
// ============================================================================

View file

@ -489,9 +489,9 @@ MENU(ConstantsMenu,
// ----------------------------------------------------------------------------
// Constants (to be loaded from catalog on disk)
// ----------------------------------------------------------------------------
"π", ID_Unimplemented,
"π", ID_pi,
"e", ID_Unimplemented,
"i", ID_Unimplemented,
"i", ID_ImaginaryUnit,
"Avogadro",ID_Unimplemented,
"Gravity", ID_Unimplemented,
"", ID_Unimplemented,

View file

@ -594,7 +594,8 @@ struct object
// Check if a type denotes a symbolic argument (symbol, equation, number)
// ------------------------------------------------------------------------
{
return ty >= FIRST_SYMBOLIC_TYPE && ty <= LAST_SYMBOLIC_TYPE;
return ((ty >= FIRST_SYMBOLIC_TYPE && ty <= LAST_SYMBOLIC_TYPE) ||
(ty >= FIRST_SYMBOLIC_CONSTANT && ty <= LAST_SYMBOLIC_CONSTANT));
}