shithub: snippets

Download patch

ref: fc4811a72c36a617ffd1bd08770aaf46cfdc80b7
parent: 27a93fee9de975149493a9a8b3cab94ed1c8df25
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Jan 13 13:24:26 EST 2021

add lrint.c

--- a/README.md
+++ b/README.md
@@ -3,5 +3,6 @@
 Random snippets of code that are in public domain.
 Just copy and use for whatever you want.
 
-* `qt.[ch]` [QP tries](https://dotat.at/prog/qp/README.html)
+* `lrint.c` lrint* implementation
 * `msr.c` MSR reading tool
+* `qt.[ch]` [QP tries](https://dotat.at/prog/qp/README.html)
--- /dev/null
+++ b/lrint.c
@@ -1,0 +1,19 @@
+int
+lrintf(float f)
+{
+	int i;
+
+	*((float*)&i) = f + 12582912.0f;
+
+	return (i & 0x7fffff) - 0x400000;
+}
+
+long
+lrint(double d)
+{
+	long long l;
+
+	*((double*)&l) = d + 6755399441055744.0;
+
+	return l;
+}