summaryrefslogtreecommitdiff
path: root/src/cr-num.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cr-num.c')
-rw-r--r--src/cr-num.c99
1 files changed, 57 insertions, 42 deletions
diff --git a/src/cr-num.c b/src/cr-num.c
index fb412a9..28c5df0 100644
--- a/src/cr-num.c
+++ b/src/cr-num.c
@@ -23,7 +23,8 @@
*/
/**
- *@file
+ *@CRNum:
+ *
*The definition
*of the #CRNum class.
*/
@@ -32,15 +33,19 @@
#include "string.h"
/**
- *The default constructor of
+ * cr_num_new:
+ *
*#CRNum.
- *@return the newly built instance of
+ *
+ *Returns the newly built instance of
*#CRNum.
*/
CRNum *
cr_num_new (void)
{
- CRNum *result = (CRNum *)g_try_malloc (sizeof (CRNum));
+ CRNum *result = NULL;
+
+ result = g_try_malloc (sizeof (CRNum));
if (result == NULL) {
cr_utils_trace_info ("Out of memory");
@@ -53,16 +58,14 @@ cr_num_new (void)
}
/**
- *A constructor of #CRNum.
- *@param a_is_natural indicates whether the intance of #CRNum is
- *a natural number or not.
- *@param a_integer_part the integer part of the instance
- *of #CRNum
- *@param a_decimal_part in case the instance of #CRNum
- *natural number (but a decimal one) this parameter
- *is the decimal part of the instance of #CRNum.
- *@return the newly built instance of #CRNum or
- *NULL if an error arises.
+ * cr_num_new_with_val:
+ * @a_val: the numerical value of the number.
+ * @a_type: the type of number.
+ *
+ * A constructor of #CRNum.
+ *
+ * Returns the newly built instance of #CRNum or
+ * NULL if an error arises.
*/
CRNum *
cr_num_new_with_val (gdouble a_val, enum CRNumType a_type)
@@ -80,16 +83,16 @@ cr_num_new_with_val (gdouble a_val, enum CRNumType a_type)
}
/**
- *Returns the string representation of the
- *current instance of #CRNum.
- *@param a_this the current instance of #CRNum.
- *@return the newly built string representation
+ * cr_num_to_string:
+ *@a_this: the current instance of #CRNum.
+ *
+ *Returns the newly built string representation
*of the current instance of #CRNum. The returned
*string is NULL terminated. The caller *must*
*free the returned string.
*/
guchar *
-cr_num_to_string (CRNum * a_this)
+cr_num_to_string (CRNum const * a_this)
{
gdouble test_val = 0.0;
@@ -102,13 +105,11 @@ cr_num_to_string (CRNum * a_this)
test_val = a_this->val - (glong) a_this->val;
if (!test_val) {
- tmp_char1 = (guchar *)g_strdup_printf ("%ld", (glong) a_this->val);
+ tmp_char1 = g_strdup_printf ("%ld", (glong) a_this->val);
} else {
- /* We can't use g_ascii_dtostr, because that sometimes uses
- e notation (which wouldn't be a valid number in CSS). */
- size_t const buflen = 35; /* fairly arbitrary. */
- tmp_char1 = (guchar *)g_malloc (buflen);
- g_ascii_formatd ((gchar *)tmp_char1, buflen, "%.15g", a_this->val);
+ tmp_char1 = g_new0 (char, G_ASCII_DTOSTR_BUF_SIZE + 1);
+ if (tmp_char1 != NULL)
+ g_ascii_dtostr (tmp_char1, G_ASCII_DTOSTR_BUF_SIZE, a_this->val);
}
g_return_val_if_fail (tmp_char1, NULL);
@@ -192,8 +193,7 @@ cr_num_to_string (CRNum * a_this)
}
if (tmp_char2) {
- result = (guchar *)g_strconcat (
- (gchar *)tmp_char1, (gchar *)tmp_char2, NULL);
+ result = g_strconcat (tmp_char1, tmp_char2, NULL);
g_free (tmp_char1);
} else {
result = tmp_char1;
@@ -203,16 +203,19 @@ cr_num_to_string (CRNum * a_this)
}
/**
- *Copies an instance of #CRNum.
- *@param a_src the instance of #CRNum to copy.
+ * cr_num_copy:
+ *@a_src: the instance of #CRNum to copy.
*Must be non NULL.
- *@param a_dst the destination of the copy.
+ *@a_dest: the destination of the copy.
*Must be non NULL
- *@return CR_OK upon successful completion, an
+ *
+ *Copies an instance of #CRNum.
+ *
+ *Returns CR_OK upon successful completion, an
*error code otherwise.
*/
enum CRStatus
-cr_num_copy (CRNum * a_dest, CRNum * a_src)
+cr_num_copy (CRNum * a_dest, CRNum const * a_src)
{
g_return_val_if_fail (a_dest && a_src, CR_BAD_PARAM_ERROR);
@@ -222,13 +225,16 @@ cr_num_copy (CRNum * a_dest, CRNum * a_src)
}
/**
+ * cr_num_dup:
+ *@a_this: the instance of #CRNum to duplicate.
+ *
*Duplicates an instance of #CRNum
- *@param a_this the instance of #CRNum to duplicate.
- *@return the newly created (duplicated) instance of #CRNum.
+ *
+ *Returns the newly created (duplicated) instance of #CRNum.
*Must be freed by cr_num_destroy().
*/
CRNum *
-cr_num_dup (CRNum * a_this)
+cr_num_dup (CRNum const * a_this)
{
CRNum *result = NULL;
enum CRStatus status = CR_OK;
@@ -245,11 +251,14 @@ cr_num_dup (CRNum * a_this)
}
/**
+ * cr_num_set:
*Sets an instance of #CRNum.
- *@param a_this the current instance of #CRNum to be set.
- *@param a_val the new numerical value to be hold by the current
+ *@a_this: the current instance of #CRNum to be set.
+ *@a_val: the new numerical value to be hold by the current
*instance of #CRNum
- *@param a_type the new type of #CRNum.
+ *@a_type: the new type of #CRNum.
+ *
+ * Returns CR_OK upon succesful completion, an error code otherwise.
*/
enum CRStatus
cr_num_set (CRNum * a_this, gdouble a_val, enum CRNumType a_type)
@@ -263,15 +272,19 @@ cr_num_set (CRNum * a_this, gdouble a_val, enum CRNumType a_type)
}
/**
+ * cr_num_is_fixed_length:
+ * @a_this: the current instance of #CRNum .
+ *
*Tests if the current instance of #CRNum is a fixed
*length value or not. Typically a fixed length value
*is anything from NUM_LENGTH_EM to NUM_LENGTH_PC.
*See the definition of #CRNumType to see what we mean.
- *@return TRUE if the instance of #CRNum is a fixed length number,
+ *
+ *Returns TRUE if the instance of #CRNum is a fixed length number,
*FALSE otherwise.
*/
gboolean
-cr_num_is_fixed_length (CRNum * a_this)
+cr_num_is_fixed_length (CRNum const * a_this)
{
gboolean result = FALSE;
@@ -285,9 +298,11 @@ cr_num_is_fixed_length (CRNum * a_this)
}
/**
- *The destructor of #CRNum.
- *@param a_this the this pointer of
+ * cr_num_destroy:
+ *@a_this: the this pointer of
*the current instance of #CRNum.
+ *
+ *The destructor of #CRNum.
*/
void
cr_num_destroy (CRNum * a_this)