[gnumeric] Functions: add HEXREP.



commit 516549397834b8d69206d0c14a447b934da58d1d
Author: Morten Welinder <terra gnome org>
Date:   Wed Nov 9 15:59:37 2011 -0500

    Functions: add HEXREP.

 NEWS                         |    1 +
 plugins/fn-eng/functions.c   |   36 ++++++++++++++++++++++++++++++++++++
 plugins/fn-eng/plugin.xml.in |    1 +
 3 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 6e5075a..f58940f 100644
--- a/NEWS
+++ b/NEWS
@@ -82,6 +82,7 @@ Morten:
 	* Embed ui files into the Gnumeric binary.
 	* Get rid of obsolete code.
 	* Add ODF.SUMPRODUCT compatibility function.  [#662551]
+	* Add HEXREP function for debugging.  [#663712]
 
 Valek:
 	* In xls import, set LABEL encoding based on FONT charset converted to 
diff --git a/plugins/fn-eng/functions.c b/plugins/fn-eng/functions.c
index 44bfe98..3f7d880 100644
--- a/plugins/fn-eng/functions.c
+++ b/plugins/fn-eng/functions.c
@@ -35,6 +35,7 @@
 #include <sheet.h>
 
 #include <goffice/goffice.h>
+#include <gsf/gsf-utils.h>
 #include <gnm-plugin.h>
 
 #include <math.h>
@@ -1169,6 +1170,37 @@ gnumeric_gestep (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_hexrep[] = {
+        { GNM_FUNC_HELP_NAME, F_("HEXREP:hexadecimal representation of numeric value") },
+        { GNM_FUNC_HELP_ARG, F_("x:number") },
+        { GNM_FUNC_HELP_DESCRIPTION, F_("HEXREP returns a hexadecimal string representation of @x.") },
+	{ GNM_FUNC_HELP_NOTE, F_("This is a function meant for debugging.  The layout of the result may change and even depend on how Gnumeric was compiled.") },
+        { GNM_FUNC_HELP_END}
+};
+
+static GnmValue *
+gnumeric_hexrep (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+	gnm_float x = value_get_as_float (argv[0]);
+	unsigned char data[sizeof(gnm_float)];
+	unsigned ui;
+	char res[2 * sizeof(gnm_float) + 1];
+	static const char hex[16] = "0123456789abcdef";
+
+	/* We don't have a long double version yet.  */
+	GSF_LE_SET_DOUBLE (data, x);
+	for (ui = 0; ui < G_N_ELEMENTS (data); ui++) {
+		unsigned char b = data[ui];
+		res[2 * ui] = hex[b >> 4];
+		res[2 * ui + 1] = hex[b & 0xf];
+	}	
+	res[2 * ui] = 0;
+
+	return value_new_string (res);
+}
+
+/***************************************************************************/
+
 static GnmFuncHelp const help_invsuminv[] = {
         { GNM_FUNC_HELP_NAME, F_("INVSUMINV:the reciprocal of the sum of reciprocals of the arguments") },
         { GNM_FUNC_HELP_ARG, F_("x0:non-negative number") },
@@ -1286,6 +1318,10 @@ GnmFuncDescriptor const engineering_functions[] = {
 	  gnumeric_hex2oct, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
 
+        { "hexrep",     "f",   help_hexrep,
+	  gnumeric_hexrep, NULL, NULL, NULL, NULL,
+	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
+
 	{ "invsuminv",    NULL,            help_invsuminv,
 	  NULL, gnumeric_invsuminv, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
diff --git a/plugins/fn-eng/plugin.xml.in b/plugins/fn-eng/plugin.xml.in
index 1105ff4..9ed3f85 100644
--- a/plugins/fn-eng/plugin.xml.in
+++ b/plugins/fn-eng/plugin.xml.in
@@ -31,6 +31,7 @@
 				<function name="hex2bin"/>
 				<function name="hex2dec"/>
 				<function name="hex2oct"/>
+				<function name="hexrep"/>
 				<function name="invsuminv"/>
 				<function name="oct2bin"/>
 				<function name="oct2dec"/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]