Skip to content

Commit e0ca4de

Browse files
committed
Cleanup remnants of BigDecimal and BigFloat
Also, remove `IntrinsicOperators`, `BignumExt`, and mentions of `math` mode. There are still some references to `math` mode in docs, but I left those as is.
1 parent ee4cd4d commit e0ca4de

File tree

6 files changed

+5
-201
lines changed

6 files changed

+5
-201
lines changed

fuzz/fuzz.dict

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"atan2"
1515
"atanh"
1616
"Atomics"
17-
"BigDecimal"
18-
"BigFloat"
19-
"BigFloatEnv"
2017
"BigInt"
2118
"BigInt64Array"
2219
"BigUint64Array"

fuzz/fuzz_common.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ void test_one_input_init(JSRuntime *rt, JSContext *ctx) {
3434
// 64 Kb
3535
JS_SetMaxStackSize(rt, 0x10000);
3636

37-
JS_AddIntrinsicBigFloat(ctx);
38-
JS_AddIntrinsicBigDecimal(ctx);
39-
JS_AddIntrinsicOperators(ctx);
40-
JS_EnableBignumExt(ctx, 1);
4137
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
4238
JS_SetInterruptHandler(JS_GetRuntime(ctx), interrupt_handler, NULL);
4339
js_std_add_helpers(ctx, 0, NULL);

quickjs.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ struct JSClass {
286286

287287
#define JS_MODE_STRICT (1 << 0)
288288
#define JS_MODE_STRIP (1 << 1)
289-
#define JS_MODE_MATH (1 << 2)
290-
#define JS_MODE_ASYNC (1 << 3) /* async function */
289+
#define JS_MODE_ASYNC (1 << 2) /* async function */
291290

292291
typedef struct JSStackFrame {
293292
struct JSStackFrame *prev_frame; /* NULL if first stack frame */
@@ -298,7 +297,7 @@ typedef struct JSStackFrame {
298297
const uint8_t *cur_pc; /* only used in bytecode functions : PC of the
299298
instruction after the call */
300299
int arg_count;
301-
int js_mode; /* for C functions, only JS_MODE_MATH may be set */
300+
int js_mode; /* not supported for C functions */
302301
/* only used in generators. Current stack pointer value. NULL if
303302
the function is running. */
304303
JSValue *cur_sp;
@@ -12871,19 +12870,6 @@ static __maybe_unused void JS_DumpValueShort(JSRuntime *rt,
1287112870
case JS_TAG_FLOAT64:
1287212871
printf("%.14g", JS_VALUE_GET_FLOAT64(val));
1287312872
break;
12874-
#if 0
12875-
/* XXX: TODO */
12876-
case JS_TAG_BIG_INT:
12877-
{
12878-
JSBigFloat *p = JS_VALUE_GET_PTR(val);
12879-
char *str;
12880-
str = bf_ftoa(NULL, &p->num, 10, 0,
12881-
BF_RNDZ | BF_FTOA_FORMAT_FRAC);
12882-
printf("%sn", str);
12883-
bf_realloc(&rt->bf_ctx, str, 0);
12884-
}
12885-
break;
12886-
#endif
1288712873
case JS_TAG_STRING:
1288812874
{
1288912875
JSString *p;
@@ -17723,8 +17709,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1772317709
op2 = sp[-1];
1772417710
if (likely(JS_VALUE_IS_BOTH_INT(op1, op2))) {
1772517711
int v1, v2;
17726-
if (unlikely(sf->js_mode & JS_MODE_MATH))
17727-
goto binary_arith_slow;
1772817712
v1 = JS_VALUE_GET_INT(op1);
1772917713
v2 = JS_VALUE_GET_INT(op2);
1773017714
sp[-2] = JS_NewFloat64(ctx, (double)v1 / (double)v2);
@@ -44666,7 +44650,6 @@ static JSValue js_json_check(JSContext *ctx, JSONStringifyContext *jsc,
4466644650

4466744651
/* check for object.toJSON method */
4466844652
/* ECMA specifies this is done only for Object and BigInt */
44669-
/* we do it for BigFloat and BigDecimal as an extension */
4467044653
if (JS_IsObject(val) || JS_IsBigInt(ctx, val)) {
4467144654
JSValue f = JS_GetProperty(ctx, val, JS_ATOM_toJSON);
4467244655
if (JS_IsException(f))

quickjs.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ typedef uint32_t JSAtom;
7474

7575
enum {
7676
/* all tags with a reference count are negative */
77-
JS_TAG_FIRST = -11, /* first negative tag */
78-
JS_TAG_BIG_DECIMAL = -11,
77+
JS_TAG_FIRST = -10, /* first negative tag */
7978
JS_TAG_BIG_INT = -10,
80-
JS_TAG_BIG_FLOAT = -9,
8179
JS_TAG_SYMBOL = -8,
8280
JS_TAG_STRING = -7,
8381
JS_TAG_MODULE = -3, /* used internally */
@@ -409,12 +407,6 @@ void JS_AddIntrinsicMapSet(JSContext *ctx);
409407
void JS_AddIntrinsicTypedArrays(JSContext *ctx);
410408
void JS_AddIntrinsicPromise(JSContext *ctx);
411409
void JS_AddIntrinsicBigInt(JSContext *ctx);
412-
void JS_AddIntrinsicBigFloat(JSContext *ctx);
413-
void JS_AddIntrinsicBigDecimal(JSContext *ctx);
414-
/* enable operator overloading */
415-
void JS_AddIntrinsicOperators(JSContext *ctx);
416-
/* enable "use math" */
417-
void JS_EnableBignumExt(JSContext *ctx, JS_BOOL enable);
418410

419411
JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
420412
int argc, JSValueConst *argv);
@@ -614,18 +606,6 @@ static inline JS_BOOL JS_IsBigInt(JSContext *ctx, JSValueConst v)
614606
return tag == JS_TAG_BIG_INT || tag == JS_TAG_SHORT_BIG_INT;
615607
}
616608

617-
static inline JS_BOOL JS_IsBigFloat(JSValueConst v)
618-
{
619-
int tag = JS_VALUE_GET_TAG(v);
620-
return tag == JS_TAG_BIG_FLOAT;
621-
}
622-
623-
static inline JS_BOOL JS_IsBigDecimal(JSValueConst v)
624-
{
625-
int tag = JS_VALUE_GET_TAG(v);
626-
return tag == JS_TAG_BIG_DECIMAL;
627-
}
628-
629609
static inline JS_BOOL JS_IsBool(JSValueConst v)
630610
{
631611
return JS_VALUE_GET_TAG(v) == JS_TAG_BOOL;

repl.js

Lines changed: 2 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ import * as os from "os";
4343

4444
/* XXX: use preprocessor ? */
4545
var config_numcalc = (typeof os.open === "undefined");
46-
var has_jscalc = (typeof Fraction === "function");
47-
var has_bignum = (typeof BigFloat === "function");
4846

4947
var colors = {
5048
none: "\x1b[0m",
@@ -913,48 +911,6 @@ import * as os from "os";
913911
}
914912
}
915913

916-
function bigfloat_to_string(a, radix) {
917-
var s;
918-
if (!BigFloat.isFinite(a)) {
919-
/* NaN, Infinite */
920-
if (eval_mode !== "math") {
921-
return "BigFloat(" + a.toString() + ")";
922-
} else {
923-
return a.toString();
924-
}
925-
} else {
926-
if (a == 0) {
927-
if (1 / a < 0)
928-
s = "-0";
929-
else
930-
s = "0";
931-
} else {
932-
if (radix == 16) {
933-
var s;
934-
if (a < 0) {
935-
a = -a;
936-
s = "-";
937-
} else {
938-
s = "";
939-
}
940-
s += "0x" + a.toString(16);
941-
} else {
942-
s = a.toString();
943-
}
944-
}
945-
if (typeof a === "bigfloat" && eval_mode !== "math") {
946-
s += "l";
947-
} else if (eval_mode !== "std" && s.indexOf(".") < 0 &&
948-
((radix == 16 && s.indexOf("p") < 0) ||
949-
(radix == 10 && s.indexOf("e") < 0))) {
950-
/* add a decimal point so that the floating point type
951-
is visible */
952-
s += ".0";
953-
}
954-
return s;
955-
}
956-
}
957-
958914
function bigint_to_string(a, radix) {
959915
var s;
960916
if (radix == 16) {
@@ -1041,10 +997,6 @@ import * as os from "os";
1041997
std.puts(number_to_string(a, hex_mode ? 16 : 10));
1042998
} else if (type === "bigint") {
1043999
std.puts(bigint_to_string(a, hex_mode ? 16 : 10));
1044-
} else if (type === "bigfloat") {
1045-
std.puts(bigfloat_to_string(a, hex_mode ? 16 : 10));
1046-
} else if (type === "bigdecimal") {
1047-
std.puts(a.toString() + "m");
10481000
} else if (type === "symbol") {
10491001
std.puts(String(a));
10501002
} else if (type === "function") {
@@ -1085,67 +1037,6 @@ import * as os from "os";
10851037
hex_mode = false;
10861038
} else if (cmd === "t") {
10871039
show_time = !show_time;
1088-
} else if (has_bignum && cmd === "p") {
1089-
param = expr.substring(cmd.length + 1).trim().split(" ");
1090-
if (param.length === 1 && param[0] === "") {
1091-
std.puts("BigFloat precision=" + prec + " bits (~" +
1092-
Math.floor(prec / log2_10) +
1093-
" digits), exponent size=" + expBits + " bits\n");
1094-
} else if (param[0] === "f16") {
1095-
prec = 11;
1096-
expBits = 5;
1097-
} else if (param[0] === "f32") {
1098-
prec = 24;
1099-
expBits = 8;
1100-
} else if (param[0] === "f64") {
1101-
prec = 53;
1102-
expBits = 11;
1103-
} else if (param[0] === "f128") {
1104-
prec = 113;
1105-
expBits = 15;
1106-
} else {
1107-
prec1 = parseInt(param[0]);
1108-
if (param.length >= 2)
1109-
expBits1 = parseInt(param[1]);
1110-
else
1111-
expBits1 = BigFloatEnv.expBitsMax;
1112-
if (Number.isNaN(prec1) ||
1113-
prec1 < BigFloatEnv.precMin ||
1114-
prec1 > BigFloatEnv.precMax) {
1115-
std.puts("Invalid precision\n");
1116-
return false;
1117-
}
1118-
if (Number.isNaN(expBits1) ||
1119-
expBits1 < BigFloatEnv.expBitsMin ||
1120-
expBits1 > BigFloatEnv.expBitsMax) {
1121-
std.puts("Invalid exponent bits\n");
1122-
return false;
1123-
}
1124-
prec = prec1;
1125-
expBits = expBits1;
1126-
}
1127-
return false;
1128-
} else if (has_bignum && cmd === "digits") {
1129-
param = expr.substring(cmd.length + 1).trim();
1130-
prec1 = Math.ceil(parseFloat(param) * log2_10);
1131-
if (prec1 < BigFloatEnv.precMin ||
1132-
prec1 > BigFloatEnv.precMax) {
1133-
std.puts("Invalid precision\n");
1134-
return false;
1135-
}
1136-
prec = prec1;
1137-
expBits = BigFloatEnv.expBitsMax;
1138-
return false;
1139-
} else if (has_bignum && cmd === "mode") {
1140-
param = expr.substring(cmd.length + 1).trim();
1141-
if (param === "") {
1142-
std.puts("Running mode=" + eval_mode + "\n");
1143-
} else if (param === "std" || param === "math") {
1144-
eval_mode = param;
1145-
} else {
1146-
std.puts("Invalid mode\n");
1147-
}
1148-
return false;
11491040
} else if (cmd === "clear") {
11501041
std.puts("\x1b[H\x1b[J");
11511042
} else if (cmd === "q") {
@@ -1207,17 +1098,6 @@ import * as os from "os";
12071098
"\\d " + sel(!hex_mode) + "decimal number display\n" +
12081099
"\\t " + sel(show_time) + "toggle timing display\n" +
12091100
"\\clear clear the terminal\n");
1210-
if (has_jscalc) {
1211-
std.puts("\\a " + sel(algebraicMode) + "algebraic mode\n" +
1212-
"\\n " + sel(!algebraicMode) + "numeric mode\n");
1213-
}
1214-
if (has_bignum) {
1215-
std.puts("\\p [m [e]] set the BigFloat precision to 'm' bits\n" +
1216-
"\\digits n set the BigFloat precision to 'ceil(n*log2(10))' bits\n");
1217-
if (!has_jscalc) {
1218-
std.puts("\\mode [std|math] change the running mode (current = " + eval_mode + ")\n");
1219-
}
1220-
}
12211101
if (!config_numcalc) {
12221102
std.puts("\\q exit\n");
12231103
}
@@ -1230,16 +1110,6 @@ import * as os from "os";
12301110
else
12311111
std.puts('QuickJS - Type "\\h" for help\n');
12321112
}
1233-
if (has_bignum) {
1234-
log2_10 = Math.log(10) / Math.log(2);
1235-
prec = 113;
1236-
expBits = 15;
1237-
if (has_jscalc) {
1238-
eval_mode = "math";
1239-
/* XXX: numeric mode should always be the default ? */
1240-
g.algebraicMode = config_numcalc;
1241-
}
1242-
}
12431113

12441114
cmd_readline_start();
12451115
}
@@ -1287,22 +1157,15 @@ import * as os from "os";
12871157
}
12881158
mexpr = "";
12891159

1290-
if (has_bignum) {
1291-
/* XXX: async is not supported in this case */
1292-
BigFloatEnv.setPrec(eval_and_print_start.bind(null, expr, false),
1293-
prec, expBits);
1294-
} else {
1295-
eval_and_print_start(expr, true);
1296-
}
1160+
eval_and_print_start(expr, true);
1161+
12971162
return true;
12981163
}
12991164

13001165
function eval_and_print_start(expr, is_async) {
13011166
var result;
13021167

13031168
try {
1304-
if (eval_mode === "math")
1305-
expr = '"use math"; void 0;' + expr;
13061169
eval_start_time = os.now();
13071170
/* eval as a script */
13081171
result = std.evalScript(expr, { backtrace_barrier: true, async: is_async });

tests/test_bjson.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,6 @@ function bjson_test_all()
155155
bjson_test([BigInt("1"), -BigInt("0x123456789"),
156156
BigInt("0x123456789abcdef123456789abcdef")]);
157157
}
158-
if (typeof BigFloat !== "undefined") {
159-
BigFloatEnv.setPrec(function () {
160-
bjson_test([BigFloat("0.1"), BigFloat("-1e30"), BigFloat("0"),
161-
BigFloat("-0"), BigFloat("Infinity"), BigFloat("-Infinity"),
162-
0.0 / BigFloat("0"), BigFloat.MAX_VALUE,
163-
BigFloat.MIN_VALUE]);
164-
}, 113, 15);
165-
}
166-
if (typeof BigDecimal !== "undefined") {
167-
bjson_test([BigDecimal("0"),
168-
BigDecimal("0.8"), BigDecimal("123321312321321e100"),
169-
BigDecimal("-1233213123213214332333223332e100"),
170-
BigDecimal("1.233e-1000")]);
171-
}
172-
173158
bjson_test([new Date(1234), new String("abc"), new Number(-12.1), new Boolean(true)]);
174159

175160
bjson_test(new Int32Array([123123, 222111, -32222]));

0 commit comments

Comments
 (0)