Skip to content

afcidk/kcalc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kcalc: Math expression evaluation as Linux kernel module

Floating point representation

This is our customized form to represent floating point, one 32-bit size is divided into sign (1 bit), integer (27 bits), and mantissa (4 bits).

msb 0    1                              28        32 lsb
    +----+------------------------------+----------+
    |sign|           integer            | mantissa |
    +----+------------------------------+----------+

Usage:

Build and install the module

$ make
$ sudo insmod calc.ko
$ sudo chmod 0666 /dev/calc

Then simply send the expression to the module

$ echo -ne "3*5\0" > /dev/calc

The expected output in dmesg should be:

CALC: Received 3 -> 3*5
Result: 240

The result seems incorrect since we do not transform the value to normal representation.

You can use add additional expression in scripts/test.sh for more examples.

$ scripts/test.sh

... Information generated by modinfo ...

Testing  6*7 ...
42
Testing  1980+1 ...
1981
Testing  2019-1 ...
2018
Testing  42/6 ...
7
Testing  1/3 ...
.33333330000000000000
Testing  1/3*6+2/4 ...
2.49999980000000000000
Testing  (1/3)+(2/3) ...
.99999990000000000000
Testing  (2145%31)+23 ...
29

About

Math expression evaluation as Linux kernel module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 87.8%
  • Shell 11.1%
  • Makefile 1.1%