aboutsummaryrefslogtreecommitdiff
path: root/libclc/generic/lib/math/log10.inc
diff options
context:
space:
mode:
Diffstat (limited to 'libclc/generic/lib/math/log10.inc')
-rw-r--r--libclc/generic/lib/math/log10.inc13
1 files changed, 13 insertions, 0 deletions
diff --git a/libclc/generic/lib/math/log10.inc b/libclc/generic/lib/math/log10.inc
new file mode 100644
index 0000000..423308a0
--- /dev/null
+++ b/libclc/generic/lib/math/log10.inc
@@ -0,0 +1,13 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE log10(__CLC_GENTYPE val) {
+ // log10(x) = log2(x) / log2(10)
+ // 1 / log2(10) = 0.30102999566 = log10(2)
+ // SP representation is 0.30103 (0x1.344136p-2)
+ // DP representation is 0.301029995659999993762312442414(0x1.34413509E61D8p-2)
+#if __CLC_FPSIZE == 32
+ return log2(val) * 0x1.344136p-2f;
+#elif __CLC_FPSIZE == 64
+ return log2(val) * 0x1.34413509E61D8p-2;
+#else
+#error unknown _CLC_FPSIZE
+#endif
+}