New man pages, trivial test case for Coord
authorfluffymormegil <mpread@chiark.greenend.org.uk>
Sun, 24 Oct 2010 00:10:43 +0000 (01:10 +0100)
committerfluffymormegil <mpread@chiark.greenend.org.uk>
Sun, 24 Oct 2010 00:10:43 +0000 (01:10 +0100)
examples/coord-test.cc [new file with mode: 0644]
man/libmormegil::div_up.3 [new file with mode: 0644]
man/libmormegil::sign.3 [new file with mode: 0644]

diff --git a/examples/coord-test.cc b/examples/coord-test.cc
new file mode 100644 (file)
index 0000000..9fd7f8e
--- /dev/null
@@ -0,0 +1,45 @@
+// examples/coord-test.cc
+//
+// Copyright 2010 Martin Read. All rights reserved.
+// 
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+// 1. Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the distribution.
+// 3. Neither the name of the author nor the names of any other contributors
+//    may be used to endorse or promote products derived from this software
+//    without their specific prior written permission.
+// 
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE.
+
+#include <stdio.h>
+#include <stdint.h>
+#include <libmormegil/Coord.hh>
+
+int main()
+{
+    libmormegil::Coord c1 = { 16, -23 };
+    libmormegil::Coord c2 = { 9, 47 };
+    libmormegil::Offset o = c2 - c1;
+    printf("c1: %d, %d\n", c1.y, c1.x);
+    printf("c2: %d, %d\n", c2.y, c2.x);
+    printf("o: %d, %d\n", o.y, o.x);
+    return 0;
+}
+
+// vim:ts=8:sw=4:expandtab:fo=cq
+// dice-test.cc
diff --git a/man/libmormegil::div_up.3 b/man/libmormegil::div_up.3
new file mode 100644 (file)
index 0000000..d600de2
--- /dev/null
@@ -0,0 +1,32 @@
+.TH "LIBMORMEGIL::DIV_UP" 3 "October 10, 2010" "libmormegil Version 1.0" "libmormegil User Manual"
+.SH NAME
+libmormegil::div_up \- integer divide rounding upwards
+.SH SYNOPSIS
+#include <libmormegil/mathops.hh>
+
+template<typename T> T libmormegil::div_up(T orig, T divisor);
+
+.SH DESCRIPTION
+.I libmormegil::div_up
+is a naively written template for upward-rounding integer division.
+
+This function exists because not all the world is an x86, and integer to
+floating point conversion is \fIpainfully\fIP awkward on at least one major
+load-store architecture.
+
+.SH RETURNS
+The rounded-up result of dividing \fIorig\fP by \fIdivisor\fP.
+
+.SH CAVEATS
+
+Implemented as naively as possible.
+
+May not do what you want if \fIorig\fP is negative. I happen to try to avoid
+dividing negative integers anyway.
+
+.SH AUTHOR
+Martin Read <mpread@chiark.greenend.org.uk>
+
+.SH SEE ALSO
+
+libmormegil(3)
diff --git a/man/libmormegil::sign.3 b/man/libmormegil::sign.3
new file mode 100644 (file)
index 0000000..5dcc2a4
--- /dev/null
@@ -0,0 +1,26 @@
+.TH "LIBMORMEGIL::SIGN" 3 "October 10, 2010" "libmormegil Version 1.0" "libmormegil User Manual"
+.SH NAME
+libmormegil::sign \- compute absolute value
+.SH SYNOPSIS
+#include <libmormegil/mathops.hh>
+
+template<typename T> T libmormegil::sign(const T& orig);
+
+.SH DESCRIPTION
+.I libmormegil::sign
+is a naively written template for obtaining the sign of \fIorig\fP.
+
+.SH RETURNS
+1 if \fIorig\fP is positive, 0 if \fIorig\fP is 0, -1 if orig is negative.
+
+.SH CAVEATS
+
+Implemented as naively as possible. Exists because <algorithm> does not
+provide such a feature.
+
+.SH AUTHOR
+Martin Read <mpread@chiark.greenend.org.uk>
+
+.SH SEE ALSO
+
+libmormegil(3)