{"id":28000732,"url":"https://github.com/sysprog21/kcalc-fixed","last_synced_at":"2025-05-08T23:54:28.793Z","repository":{"id":56599659,"uuid":"305532523","full_name":"sysprog21/kcalc-fixed","owner":"sysprog21","description":"Math expression evaluation as Linux kernel module, fixed-point implementation","archived":false,"fork":false,"pushed_at":"2020-10-29T13:39:08.000Z","size":66,"stargazers_count":4,"open_issues_count":0,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T23:54:20.979Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sysprog21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-19T22:56:08.000Z","updated_at":"2024-03-05T10:52:16.000Z","dependencies_parsed_at":"2022-08-15T21:40:37.419Z","dependency_job_id":null,"html_url":"https://github.com/sysprog21/kcalc-fixed","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fkcalc-fixed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fkcalc-fixed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fkcalc-fixed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fkcalc-fixed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sysprog21","download_url":"https://codeload.github.com/sysprog21/kcalc-fixed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166484,"owners_count":21864471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-08T23:54:28.176Z","updated_at":"2025-05-08T23:54:28.783Z","avatar_url":"https://github.com/sysprog21.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kcalc: in-kernel math expression evaluation for Linux\n\nkcalc is a mathematical expression evaluator and takes string as\ninput, returning fixed-point numbers.\n\n## Features\n\n* Arithmetic, bitwise and logical operators;\n* Flexiable variables;\n* Customized functions;\n\n## Fixed-point representation\n\nkcalc introduces a fixed-point number representation for fractional values.\n\n## Usage:\n\nBuild and install the module\n\n```shell\n$ make\n$ sudo insmod calc.ko\n$ sudo chmod 0666 /dev/calc\n```\n\nThen simply send the expression to the module\n\n```shell\n$ echo -ne \"3*5\\0\" \u003e /dev/calc\n```\n\nThe expected output in `dmesg` should be:\n\n```shell\ncalc: Received 3 -\u003e 3*5\nResult: 64424509440\n```\n\nThe result seems incorrect since we do not transform the value to normal representation.\nYou can use the utlity to convert values into human readable form:\n```shell\n$ ./eval 64424509440\n```\n\nThen, you can get `15.000000`, which is the exact result of expression `3*5`.\n\nYou can check file `scripts/test.sh` for more examples about the expressions. Alteratively,\nexecue `make check` for the same script.\n\n```shell\n$ scripts/test.sh\n\n... Information generated by modinfo ...\n\nTesting  6*7 ...\n42\nTesting  1980+1 ...\n1981\nTesting  2019-1 ...\n2018\nTesting  42/6 ...\n7\nTesting  1/3 ...\n.33333330000000000000\nTesting  1/3*6+2/4 ...\n2.49999980000000000000\nTesting  (1/3)+(2/3) ...\n.99999990000000000000\nTesting  (2145%31)+23 ...\n29\n```\n\n## Internals\n\n`struct expr *expr_create(const char *s, size_t len, struct expr_var_list\n*vars, struct expr_func *funcs)` - returns compiled expression from the given\nstring. If expression uses variables - they are bound to `vars`, so you can\nmodify values before evaluation or check the results after the evaluation.\n\n`int expr_eval(struct expr *e)` - evaluates compiled expression.\n\n`void expr_destroy(struct expr *e, struct expr_var_list *vars)` - cleans up\nmemory. Parameters can be NULL (e.g. if you want to clean up expression, but\nreuse variables for another expression).\n\n`struct expr_var *expr_var(struct expr_var *vars, const char *s, size_t len)` -\nreturns/creates variable of the given name in the given list. This can be used\nto get variable references to get/set them manually.\n\n## Supported operators\n\n* Arithmetics: `+`, `-`, `*`, `/`, `%` (remainder), `**` (power)\n* Bitwise: `\u003c\u003c`, `\u003e\u003e`, `\u0026`, `|`, `^` (xor or unary bitwise negation)\n* Logical: `\u003c`, `\u003e`, `==`, `!=`, `\u003c=`, `\u003e=`, `\u0026\u0026`, `||`, `!` (unary not)\n* Other: `=` (assignment, e.g. `x=y=5`), `,` (separates expressions or function parameters)\n\n## License\n\n`kcalc`is released under the MIT License. Use of this source code is governed by\na MIT License that can be found in the LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysprog21%2Fkcalc-fixed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsysprog21%2Fkcalc-fixed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysprog21%2Fkcalc-fixed/lists"}