]> gitweb.factorcode.org Git - factor.git/commitdiff
Add a couple minor extra docs for math.extras
authorBenjamin Pollack <benjamin@bitquabit.com>
Fri, 8 May 2015 21:09:46 +0000 (17:09 -0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 8 May 2015 21:12:09 +0000 (14:12 -0700)
extra/math/extras/extras-docs.factor

index 51abeaab1f0280dae232ee32b5c6dd602cf8cee1..2cc060586df375a451101afc69b121768bc06bf0 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2012 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: help.markup help.syntax kernel math sequences ;
+USING: help.markup help.syntax kernel math math.functions sequences ;
 
 IN: math.extras
 
@@ -78,6 +78,18 @@ HELP: majority
 { $values { "seq" sequence } { "elt/f" object } }
 { $description "Returns the element of " { $snippet "seq" } " that is in the majority, provided there is such an element, using a linear-time majority vote algorithm." } ;
 
+HELP: nonzero
+{ $values { "seq" sequence } { "seq'" sequence } }
+{ $description "Outputs a new sequence of the same type as " { $snippet "seq" } " with all non-zero elements removed." } ;
+
+HELP: round-away-from-zero
+{ $values { "x" number } { "y" number } }
+{ $description "Rounds " { $snippet "x" } " via " { $link ceiling } " if " { $snippet "x" } " is greater than zero, and " { $link floor } " if x is less than zero." }
+{ $examples
+    { $example "USING: math.extras prettyprint ;" "0.5 round-away-from-zero ." "1.0" }
+    { $example "USING: math.extras prettyprint ;" "-0.5 round-away-from-zero ." "-1.0" } }
+{ $see-also ceiling floor } ;
+
 HELP: round-to-decimal
 { $values { "x" real } { "n" integer } { "y" real } }
 { $description "Outputs the number closest to " { $snippet "x" } ", rounded to " { $snippet "n" } " decimal places." }
@@ -87,6 +99,13 @@ HELP: round-to-decimal
     { $example "USING: math.extras prettyprint ;" "12345.6789 -3 round-to-decimal ." "12000.0" }
 } ;
 
+HELP: round-to-even
+{ $values { "x" real } { "y" real } }
+{ $description "Rounds " { $snippet "x" } " towards the nearest even number.  This is also known as banker's rounding or unbiased rounding." }
+{ $examples
+    { $example "USING: math.extras prettyprint ;" "0.5 round-to-even ." "0.0" }
+    { $example "USING: math.extras prettyprint ;" "1.5 round-to-even ." "2.0" } } ;
+
 HELP: kahan-sum
 { $values { "seq" sequence } { "n" float } }
 { $description "Calculates the summation of the sequence using the Kahan summation algorithm." } ;