5
* Copyright (C) 1999 - 2007 Michael C. Ring
7
* Permission to use, copy, and distribute this software and its
8
* documentation for any purpose with or without fee is hereby granted,
9
* provided that the above copyright notice appear in all copies and
10
* that both that copyright notice and this permission notice appear
11
* in supporting documentation.
13
* Permission to modify the software is granted. Permission to distribute
14
* the modified code is granted. Modifications are to be distributed by
15
* using the file 'license.txt' as a template to modify the file header.
16
* 'license.txt' is available in the official MAPM distribution.
18
* This software is provided "as is" without express or implied warranty.
23
* This file contains M_APM -> integer string function
28
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
30
/****************************************************************************/
31
void m_apm_to_integer_string(char *s, M_APM mtmp)
34
UCHAR *ucp, numdiv, numrem;
35
char *cp, *p, sbuf[128];
39
ct = mtmp->m_apm_exponent;
40
dl = mtmp->m_apm_datalength;
43
* if |input| < 1, result is "0"
46
if (ct <= 0 || mtmp->m_apm_sign == 0)
55
if ((vp = (void *)MAPM_MALLOC((ct + 32) * sizeof(char))) == NULL)
57
/* fatal, this does not return */
59
M_apm_log_error_msg(M_APM_FATAL,
60
"\'m_apm_to_integer_string\', Out of memory");
73
/* handle a negative number */
75
if (mtmp->m_apm_sign == -1)
81
/* get num-bytes of data (#digits / 2) to use in the string */
88
ucp = mtmp->m_apm_data;
92
M_get_div_rem_10((int)(*ucp++), &numdiv, &numrem);
101
/* pad with trailing zeros if the exponent > datalength */
104
memset(p, '0', (ct + 1 - dl));
112
/****************************************************************************/