ported the portability fix in bigint.c

This commit is contained in:
2025-08-05 22:35:17 +09:00
parent 9afb8e3898
commit 0da2d2abd3
37 changed files with 1992 additions and 1988 deletions

View File

@ -34,7 +34,7 @@
* This file defines various formatting functions.
*/
/**
/**
* The moo_fmt_intmax_flag_t type defines enumerators to change the
* behavior of moo_fmt_intmax() and moo_fmt_uintmax().
*/
@ -163,7 +163,7 @@ typedef int (*moo_fmtout_putobj_t) (
moo_oop_t obj
);
enum moo_fmtout_fmt_type_t
enum moo_fmtout_fmt_type_t
{
MOO_FMTOUT_FMT_TYPE_BCH = 0,
MOO_FMTOUT_FMT_TYPE_UCH
@ -193,22 +193,22 @@ extern "C" {
#endif
/**
* The moo_fmt_intmax_to_bcstr() function formats an integer \a value to a
* multibyte string according to the given base and writes it to a buffer
* pointed to by \a buf. It writes to the buffer at most \a size characters
* including the terminating null. The base must be between 2 and 36 inclusive
* and can be ORed with zero or more #moo_fmt_intmax_to_bcstr_flag_t enumerators.
* This ORed value is passed to the function via the \a base_and_flags
* The moo_fmt_intmax_to_bcstr() function formats an integer \a value to a
* multibyte string according to the given base and writes it to a buffer
* pointed to by \a buf. It writes to the buffer at most \a size characters
* including the terminating null. The base must be between 2 and 36 inclusive
* and can be ORed with zero or more #moo_fmt_intmax_to_bcstr_flag_t enumerators.
* This ORed value is passed to the function via the \a base_and_flags
* parameter. If the formatted string is shorter than \a bufsize, the redundant
* slots are filled with the fill character \a fillchar if it is not a null
* slots are filled with the fill character \a fillchar if it is not a null
* character. The filling behavior is determined by the flags shown below:
*
* - If #MOO_FMT_INTMAX_TO_BCSTR_FILLRIGHT is set in \a base_and_flags, slots
* - If #MOO_FMT_INTMAX_TO_BCSTR_FILLRIGHT is set in \a base_and_flags, slots
* after the formatting string are filled.
* - If #MOO_FMT_INTMAX_TO_BCSTR_FILLCENTER is set in \a base_and_flags, slots
* - If #MOO_FMT_INTMAX_TO_BCSTR_FILLCENTER is set in \a base_and_flags, slots
* before the formatting string are filled. However, if it contains the
* sign character, the slots between the sign character and the digit part
* are filled.
* are filled.
* - If neither #MOO_FMT_INTMAX_TO_BCSTR_FILLRIGHT nor #MOO_FMT_INTMAX_TO_BCSTR_FILLCENTER
* , slots before the formatting string are filled.
*
@ -220,26 +220,26 @@ extern "C" {
*
* The terminating null is not added if #MOO_FMT_INTMAX_TO_BCSTR_NONULL is set;
* The #MOO_FMT_INTMAX_TO_BCSTR_UPPERCASE flag indicates that the function should
* use the uppercase letter for a alphabetic digit;
* use the uppercase letter for a alphabetic digit;
* You can set #MOO_FMT_INTMAX_TO_BCSTR_NOTRUNC if you require lossless formatting.
* The #MOO_FMT_INTMAX_TO_BCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_BCSTR_EMPTYSIGN
* ensures that the plus sign and a space is added for a positive integer
* The #MOO_FMT_INTMAX_TO_BCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_BCSTR_EMPTYSIGN
* ensures that the plus sign and a space is added for a positive integer
* including 0 respectively.
* The #MOO_FMT_INTMAX_TO_BCSTR_ZEROLEAD flag ensures that the numeric string
* begins with '0' before applying the prefix.
* You can set the #MOO_FMT_INTMAX_TO_BCSTR_NOZERO flag if you want the value of
* 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_BCSTR_NOZERO and
* 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_BCSTR_NOZERO and
* #MOO_FMT_INTMAX_TO_BCSTR_ZEROLEAD are specified, '0' is still produced.
*
*
* If \a prefix is not #MOO_NULL, it is inserted before the digits.
*
*
* \return
* - -1 if the base is not between 2 and 36 inclusive.
* - negated number of characters required for lossless formatting
* - -1 if the base is not between 2 and 36 inclusive.
* - negated number of characters required for lossless formatting
* - if \a bufsize is 0.
* - if #MOO_FMT_INTMAX_TO_BCSTR_NOTRUNC is set and \a bufsize is less than
* the minimum required for lossless formatting.
* - number of characters written to the buffer excluding a terminating
* - number of characters written to the buffer excluding a terminating
* null in all other cases.
*/
MOO_EXPORT int moo_fmt_intmax_to_bcstr (
@ -253,25 +253,25 @@ MOO_EXPORT int moo_fmt_intmax_to_bcstr (
);
/**
* The moo_fmt_intmax_to_ucstr() function formats an integer \a value to a
* wide-character string according to the given base and writes it to a buffer
* pointed to by \a buf. It writes to the buffer at most \a size characters
* including the terminating null. The base must be between 2 and 36 inclusive
* and can be ORed with zero or more #moo_fmt_intmax_to_ucstr_flag_t enumerators.
* This ORed value is passed to the function via the \a base_and_flags
* The moo_fmt_intmax_to_ucstr() function formats an integer \a value to a
* wide-character string according to the given base and writes it to a buffer
* pointed to by \a buf. It writes to the buffer at most \a size characters
* including the terminating null. The base must be between 2 and 36 inclusive
* and can be ORed with zero or more #moo_fmt_intmax_to_ucstr_flag_t enumerators.
* This ORed value is passed to the function via the \a base_and_flags
* parameter. If the formatted string is shorter than \a bufsize, the redundant
* slots are filled with the fill character \a fillchar if it is not a null
* slots are filled with the fill character \a fillchar if it is not a null
* character. The filling behavior is determined by the flags shown below:
*
* - If #MOO_FMT_INTMAX_TO_UCSTR_FILLRIGHT is set in \a base_and_flags, slots
* - If #MOO_FMT_INTMAX_TO_UCSTR_FILLRIGHT is set in \a base_and_flags, slots
* after the formatting string are filled.
* - If #MOO_FMT_INTMAX_TO_UCSTR_FILLCENTER is set in \a base_and_flags, slots
* - If #MOO_FMT_INTMAX_TO_UCSTR_FILLCENTER is set in \a base_and_flags, slots
* before the formatting string are filled. However, if it contains the
* sign character, the slots between the sign character and the digit part
* are filled.
* are filled.
* - If neither #MOO_FMT_INTMAX_TO_UCSTR_FILLRIGHT nor #MOO_FMT_INTMAX_TO_UCSTR_FILLCENTER
* , slots before the formatting string are filled.
*
*
* The \a precision parameter specified the minimum number of digits to
* produce from the \ value. If \a value produces fewer digits than
* \a precision, the actual digits are padded with '0' to meet the precision
@ -280,26 +280,26 @@ MOO_EXPORT int moo_fmt_intmax_to_bcstr (
*
* The terminating null is not added if #MOO_FMT_INTMAX_TO_UCSTR_NONULL is set;
* The #MOO_FMT_INTMAX_TO_UCSTR_UPPERCASE flag indicates that the function should
* use the uppercase letter for a alphabetic digit;
* use the uppercase letter for a alphabetic digit;
* You can set #MOO_FMT_INTMAX_TO_UCSTR_NOTRUNC if you require lossless formatting.
* The #MOO_FMT_INTMAX_TO_UCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_UCSTR_EMPTYSIGN
* ensures that the plus sign and a space is added for a positive integer
* The #MOO_FMT_INTMAX_TO_UCSTR_PLUSSIGN flag and #MOO_FMT_INTMAX_TO_UCSTR_EMPTYSIGN
* ensures that the plus sign and a space is added for a positive integer
* including 0 respectively.
* The #MOO_FMT_INTMAX_TO_UCSTR_ZEROLEAD flag ensures that the numeric string
* begins with 0 before applying the prefix.
* You can set the #MOO_FMT_INTMAX_TO_UCSTR_NOZERO flag if you want the value of
* 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_UCSTR_NOZERO and
* 0 to produce nothing. If both #MOO_FMT_INTMAX_TO_UCSTR_NOZERO and
* #MOO_FMT_INTMAX_TO_UCSTR_ZEROLEAD are specified, '0' is still produced.
*
* If \a prefix is not #MOO_NULL, it is inserted before the digits.
*
*
* \return
* - -1 if the base is not between 2 and 36 inclusive.
* - negated number of characters required for lossless formatting
* - -1 if the base is not between 2 and 36 inclusive.
* - negated number of characters required for lossless formatting
* - if \a bufsize is 0.
* - if #MOO_FMT_INTMAX_TO_UCSTR_NOTRUNC is set and \a bufsize is less than
* the minimum required for lossless formatting.
* - number of characters written to the buffer excluding a terminating
* - number of characters written to the buffer excluding a terminating
* null in all other cases.
*/
MOO_EXPORT int moo_fmt_intmax_to_ucstr (
@ -313,8 +313,8 @@ MOO_EXPORT int moo_fmt_intmax_to_ucstr (
);
/**
* The moo_fmt_uintmax_to_bcstr() function formats an unsigned integer \a value
* to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_bcstr()
* The moo_fmt_uintmax_to_bcstr() function formats an unsigned integer \a value
* to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_bcstr()
* except that it handles an unsigned integer.
*/
MOO_EXPORT int moo_fmt_uintmax_to_bcstr (
@ -328,8 +328,8 @@ MOO_EXPORT int moo_fmt_uintmax_to_bcstr (
);
/**
* The moo_fmt_uintmax_to_ucstr() function formats an unsigned integer \a value
* to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_ucstr()
* The moo_fmt_uintmax_to_ucstr() function formats an unsigned integer \a value
* to a multibyte string buffer. It behaves the same as moo_fmt_intmax_to_ucstr()
* except that it handles an unsigned integer.
*/
MOO_EXPORT int moo_fmt_uintmax_to_ucstr (