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, 42 insertions, 57 deletions
diff --git a/src/cr-num.c b/src/cr-num.c
index 28c5df0..fb412a9 100644
--- a/src/cr-num.c
+++ b/src/cr-num.c
@@ -23,8 +23,7 @@
*/
/**
- *@CRNum:
- *
+ *@file
*The definition
*of the #CRNum class.
*/
@@ -33,19 +32,15 @@
#include "string.h"
/**
- * cr_num_new:
- *
+ *The default constructor of
*#CRNum.
- *
- *Returns the newly built instance of
+ *@return the newly built instance of
*#CRNum.
*/
CRNum *
cr_num_new (void)
{
- CRNum *result = NULL;
-
- result = g_try_malloc (sizeof (CRNum));
+ CRNum *result = (CRNum *)g_try_malloc (sizeof (CRNum));
if (result == NULL) {
cr_utils_trace_info ("Out of memory");
@@ -58,14 +53,16 @@ cr_num_new (void)
}
/**
- * 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.
+ *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.
*/
CRNum *
cr_num_new_with_val (gdouble a_val, enum CRNumType a_type)
@@ -83,16 +80,16 @@ cr_num_new_with_val (gdouble a_val, enum CRNumType a_type)
}
/**
- * cr_num_to_string:
- *@a_this: the current instance of #CRNum.
- *
- *Returns the newly built string representation
+ *Returns the string representation of the
+ *current instance of #CRNum.
+ *@param a_this the current instance of #CRNum.
+ *@return 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 const * a_this)
+cr_num_to_string (CRNum * a_this)
{
gdouble test_val = 0.0;
@@ -105,11 +102,13 @@ cr_num_to_string (CRNum const * a_this)
test_val = a_this->val - (glong) a_this->val;
if (!test_val) {
- tmp_char1 = g_strdup_printf ("%ld", (glong) a_this->val);
+ tmp_char1 = (guchar *)g_strdup_printf ("%ld", (glong) a_this->val);
} else {
- 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);
+ /* 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);
}
g_return_val_if_fail (tmp_char1, NULL);
@@ -193,7 +192,8 @@ cr_num_to_string (CRNum const * a_this)
}
if (tmp_char2) {
- result = g_strconcat (tmp_char1, tmp_char2, NULL);
+ result = (guchar *)g_strconcat (
+ (gchar *)tmp_char1, (gchar *)tmp_char2, NULL);
g_free (tmp_char1);
} else {
result = tmp_char1;
@@ -203,19 +203,16 @@ cr_num_to_string (CRNum const * a_this)
}
/**
- * cr_num_copy:
- *@a_src: the instance of #CRNum to copy.
+ *Copies an instance of #CRNum.
+ *@param a_src the instance of #CRNum to copy.
*Must be non NULL.
- *@a_dest: the destination of the copy.
+ *@param a_dst the destination of the copy.
*Must be non NULL
- *
- *Copies an instance of #CRNum.
- *
- *Returns CR_OK upon successful completion, an
+ *@return CR_OK upon successful completion, an
*error code otherwise.
*/
enum CRStatus
-cr_num_copy (CRNum * a_dest, CRNum const * a_src)
+cr_num_copy (CRNum * a_dest, CRNum * a_src)
{
g_return_val_if_fail (a_dest && a_src, CR_BAD_PARAM_ERROR);
@@ -225,16 +222,13 @@ cr_num_copy (CRNum * a_dest, CRNum const * a_src)
}
/**
- * cr_num_dup:
- *@a_this: the instance of #CRNum to duplicate.
- *
*Duplicates an instance of #CRNum
- *
- *Returns the newly created (duplicated) instance of #CRNum.
+ *@param a_this the instance of #CRNum to duplicate.
+ *@return the newly created (duplicated) instance of #CRNum.
*Must be freed by cr_num_destroy().
*/
CRNum *
-cr_num_dup (CRNum const * a_this)
+cr_num_dup (CRNum * a_this)
{
CRNum *result = NULL;
enum CRStatus status = CR_OK;
@@ -251,14 +245,11 @@ cr_num_dup (CRNum const * a_this)
}
/**
- * cr_num_set:
*Sets an instance of #CRNum.
- *@a_this: the current instance of #CRNum to be set.
- *@a_val: the new numerical value to be hold by the current
+ *@param a_this the current instance of #CRNum to be set.
+ *@param a_val the new numerical value to be hold by the current
*instance of #CRNum
- *@a_type: the new type of #CRNum.
- *
- * Returns CR_OK upon succesful completion, an error code otherwise.
+ *@param a_type the new type of #CRNum.
*/
enum CRStatus
cr_num_set (CRNum * a_this, gdouble a_val, enum CRNumType a_type)
@@ -272,19 +263,15 @@ 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.
- *
- *Returns TRUE if the instance of #CRNum is a fixed length number,
+ *@return TRUE if the instance of #CRNum is a fixed length number,
*FALSE otherwise.
*/
gboolean
-cr_num_is_fixed_length (CRNum const * a_this)
+cr_num_is_fixed_length (CRNum * a_this)
{
gboolean result = FALSE;
@@ -298,11 +285,9 @@ cr_num_is_fixed_length (CRNum const * a_this)
}
/**
- * cr_num_destroy:
- *@a_this: the this pointer of
- *the current instance of #CRNum.
- *
*The destructor of #CRNum.
+ *@param a_this the this pointer of
+ *the current instance of #CRNum.
*/
void
cr_num_destroy (CRNum * a_this)