From 4676b84c4c0ce28c0cc4e3fed38533f3357ad63b Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 27 Nov 2019 00:23:50 +0100 Subject: [PATCH] Now in OS/K : floats ! --- kaleid/kernel/sh/shcmds.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) 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" },