handle decimals

This commit is contained in:
Zander Thannhauser 2025-08-03 23:03:48 -05:00
parent 5bed7b557a
commit dbd3ff2acd
3 changed files with 17 additions and 2 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.direnv/
bin/
outputs/
*.swp

View file

@ -39,7 +39,7 @@
pname = "qc";
version = "1.0";
src = ./.;
nativeBuildInputs = with pkgs; [ gcc gnumake readline.dev gmp.dev ];
nativeBuildInputs = with pkgs; [ gcc gnumake ];
buildInputs = with pkgs; [ readline.dev gmp.dev ];
};
});

16
main.c
View file

@ -377,7 +377,20 @@ struct value* scan(const char* text)
{
mpq_t factor; mpq_init(factor);
TODO;
moving++;
mpq_set_si(factor, 1, 10);
while ('0' <= *moving && *moving <= '9')
{
mpq_set_si(tmp, *moving++ - '0', 1);
mpq_mul(tmp, factor, tmp);
mpq_add(value, value, tmp);
mpq_div(factor, factor, base);
}
mpq_clear(factor);
}
@ -570,6 +583,7 @@ struct expression* parse(const char* text)
while (false
|| *moving == '_'
|| *moving == '.'
|| ('0' <= *moving && *moving <= '9'))
{
append(*moving++);