diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index 14247b4..7bfc17a 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -164,24 +164,26 @@ error_t CmdDumpATASect(int argc, char **argv, char *cmdline) return EOK; } -error_t CmdFloat(int argc, char **argv, char *cmdline) +error_t CmdFloatDiv(int argc, char **argv, char *cmdline) { - double param = (double)ShAtoi(argv[1]); + double a = (double)ShAtoi(argv[1]); + double b = (double)ShAtoi(argv[2]); - double b = 138899.009 / (14.9); //9322,0811409 + double number = a / b; + double number_ent = (double)(ulong)number; + double dec = number - number_ent; + double sub = 0.0; - double b_ent = (double)(ulong)b; - double dec = 0.0; + char res[17]; // 10e-16 is the max precision - KernLog("int(b) = %d \n", (ulong)b_ent); - KernLog("dec(b) = "); + for(int i = 0; i < 16; i++) { + dec = (dec * 10.0) - (sub * 10.0); + sub = (double)(ulong)dec; - for(double i = 0; i < param; i++) { - dec = ; - KernLog("%d", (ulong)dec); + snprintf(&res[i], 17-i, "%d", (ulong)dec); } - KernLog("\n"); + KernLog("%d / %d = %d.%s \n", (ulong)a, (ulong)b, (ulong)number_ent, res); return EOK; } @@ -362,7 +364,7 @@ static Command_t testcmdtable[] = { "help", CmdHelpTest, "Show this message" }, { "pf", CmdPF, "Provoke a PF. Usage: pfault
"}, { "ps", CmdPsTest, "Scheduler test routine" }, - { "float", CmdFloat, "Float test" }, + { "div", CmdFloatDiv, "Float div. Usage : div a b. Returns a/b"}, { "rpag", CmdReloadPage, "Reload the pages directory" }, { "shell", CmdShell, "Start a new shell (nested)", }, { "stkov", CmdStackOverflow, "Provoke a stack overflow" },