+export const {
+ /**
+ * Returns the result of converting the provided value to an
+ * exponential notation string.
+ *
+ * If a second argument is provided, it gives the number of
+ * fractional digits to use in the mantissa. Otherwise, the smallest
+ * number which does not result in a reduction in precision is used.
+ *
+ * ※ This method is safe to use with big·ints.
+ */
+ toExponentialNotation,
+
+ /**
+ * Returns the result of converting the provided value to a fixed
+ * decimal notation string with the provided number of fractional
+ * digits.
+ *
+ * ※ This method is safe to use with big·ints.
+ */
+ toFixedDecimalNotation,
+} = (() => {
+ const {
+ toExponential: numberToExponential,
+ toFixed: numberToFixed,
+ } = Number.prototype;
+ const { toString: bigintToString } = BigInt.prototype;
+ return {
+ toExponentialNotation: ($, fractionDigits) => {
+ const n = toNumeric($);
+ const f = toIntegralNumberOrInfinity(fractionDigits);
+ if (!isFiniteNumber(f) || f < 0 || f > 100) {
+ throw new RangeError(
+ `Piscēs: The number of fractional digits must be a finite number between 0 and 100 inclusive; got: ${f}.`,
+ );
+ } else {
+ if (typeof n === "number") {
+ return call(
+ numberToExponential,
+ n,
+ [fractionDigits === undefined ? fractionDigits : f],
+ );
+ } else {
+ const digits = call(bigintToString, n, [10]);
+ const { length } = digits;
+ if (fractionDigits === undefined) {
+ return length === 1
+ ? `${digits[0]}e+0`
+ : `${digits[0]}.${substring(digits, 1)}e+${length - 1}`;
+ } else if (f === 0) {
+ return `${digits[0]}e+0`;
+ } else {
+ const fractionalPart = toString(
+ round(
+ +stringCatenate(
+ stringPadEnd(substring(digits, 1, f + 1), f, "0"),
+ ".",
+ digits[f + 1] || "0",
+ ),
+ ),
+ );
+ return `${digits[0]}.${fractionalPart}e+${length - 1}`;
+ }
+ }
+ }
+ },
+ toFixedDecimalNotation: ($, fractionDigits) => {
+ const f = toIntegralNumberOrInfinity(fractionDigits);
+ if (!isFiniteNumber(f) || f < 0 || f > 100) {
+ throw new RangeError(
+ `Piscēs: The number of fractional digits must be a finite number between 0 and 100 inclusive; got: ${f}.`,
+ );
+ } else {
+ const n = toNumeric($);
+ if (typeof n === "number") {
+ return call(numberToFixed, n, [f]);
+ } else {
+ const digits = call(bigintToString, n, [10]);
+ return f === 0
+ ? digits
+ : `${digits}.${stringRepeat("0", f)}`;
+ }
+ }
+ },
+ };
+})();
+