[OpenBIOS] r330 - forth/lib

svn at openbios.org svn at openbios.org
Sat Apr 28 00:17:01 CEST 2007


Author: wmb
Date: 2007-04-28 00:17:00 +0200 (Sat, 28 Apr 2007)
New Revision: 330

Modified:
   forth/lib/util.fth
Log:
Added rounded-/ to forth/lib/util.fth so it can be used more generally.



Modified: forth/lib/util.fth
===================================================================
--- forth/lib/util.fth	2007-04-27 21:50:36 UTC (rev 329)
+++ forth/lib/util.fth	2007-04-27 22:17:00 UTC (rev 330)
@@ -135,6 +135,13 @@
 \ : ux.  ( adr -- )  base @ >r  hex  (u.) type  r> base !  ;
 \ ' ux. is showaddr
 
+\ Integer division which rounds to nearest instead of truncating
+: rounded-/  ( dividend divisor -- rounded-result )
+   swap 2*  swap /  ( result*2 )
+   dup 1 and +      \ add 1 to the result if it is odd
+   2/               ( rounded-result )
+;
+
 \ LICENSE_BEGIN
 \ Copyright (c) 2006 FirmWorks
 \ 




More information about the OpenBIOS mailing list