libdecnumber: Introduce decNumberFrom[U]Int64
Introduce two conversion functions to the libdecnumber library. These conversions transform 64 bit integers to the internal decNumber representation. Both a signed and unsigned version is added. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
e58f8d1ff9
commit
8e706db21e
@ -115,6 +115,8 @@
|
|||||||
/* Conversions */
|
/* Conversions */
|
||||||
decNumber * decNumberFromInt32(decNumber *, int32_t);
|
decNumber * decNumberFromInt32(decNumber *, int32_t);
|
||||||
decNumber * decNumberFromUInt32(decNumber *, uint32_t);
|
decNumber * decNumberFromUInt32(decNumber *, uint32_t);
|
||||||
|
decNumber *decNumberFromInt64(decNumber *, int64_t);
|
||||||
|
decNumber *decNumberFromUInt64(decNumber *, uint64_t);
|
||||||
decNumber * decNumberFromString(decNumber *, const char *, decContext *);
|
decNumber * decNumberFromString(decNumber *, const char *, decContext *);
|
||||||
char * decNumberToString(const decNumber *, char *);
|
char * decNumberToString(const decNumber *, char *);
|
||||||
char * decNumberToEngString(const decNumber *, char *);
|
char * decNumberToEngString(const decNumber *, char *);
|
||||||
|
@ -436,6 +436,36 @@ uInt decNumberToUInt32(const decNumber *dn, decContext *set) {
|
|||||||
return 0;
|
return 0;
|
||||||
} /* decNumberToUInt32 */
|
} /* decNumberToUInt32 */
|
||||||
|
|
||||||
|
decNumber *decNumberFromInt64(decNumber *dn, int64_t in)
|
||||||
|
{
|
||||||
|
uint64_t unsig = in;
|
||||||
|
if (in < 0) {
|
||||||
|
unsig = -unsig;
|
||||||
|
}
|
||||||
|
|
||||||
|
decNumberFromUInt64(dn, unsig);
|
||||||
|
if (in < 0) {
|
||||||
|
dn->bits = DECNEG; /* sign needed */
|
||||||
|
}
|
||||||
|
return dn;
|
||||||
|
} /* decNumberFromInt64 */
|
||||||
|
|
||||||
|
decNumber *decNumberFromUInt64(decNumber *dn, uint64_t uin)
|
||||||
|
{
|
||||||
|
Unit *up; /* work pointer */
|
||||||
|
decNumberZero(dn); /* clean */
|
||||||
|
if (uin == 0) {
|
||||||
|
return dn; /* [or decGetDigits bad call] */
|
||||||
|
}
|
||||||
|
for (up = dn->lsu; uin > 0; up++) {
|
||||||
|
*up = (Unit)(uin % (DECDPUNMAX + 1));
|
||||||
|
uin = uin / (DECDPUNMAX + 1);
|
||||||
|
}
|
||||||
|
dn->digits = decGetDigits(dn->lsu, up-dn->lsu);
|
||||||
|
return dn;
|
||||||
|
} /* decNumberFromUInt64 */
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
/* to-scientific-string -- conversion to numeric string */
|
/* to-scientific-string -- conversion to numeric string */
|
||||||
/* to-engineering-string -- conversion to numeric string */
|
/* to-engineering-string -- conversion to numeric string */
|
||||||
|
Loading…
Reference in New Issue
Block a user