mirror of
https://github.com/janet-lang/janet
synced 2025-06-03 07:04:12 +00:00
Add hexfloats - Address #1550
This commit is contained in:
parent
fa75a395cb
commit
f63a33884f
@ -298,8 +298,10 @@ int janet_scan_number_base(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If still base is 0, set to default (10) */
|
/* If still base is 0, set to default (10) */
|
||||||
|
int exp_base = base;
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
base = 10;
|
base = 10;
|
||||||
|
exp_base = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip leading zeros */
|
/* Skip leading zeros */
|
||||||
@ -322,6 +324,12 @@ int janet_scan_number_base(
|
|||||||
} else if (*str == '&') {
|
} else if (*str == '&') {
|
||||||
foundexp = 1;
|
foundexp = 1;
|
||||||
break;
|
break;
|
||||||
|
} else if (base == 16 && (*str == 'P' || *str == 'p')) { /* IEEE hex float */
|
||||||
|
foundexp = 1;
|
||||||
|
exp_base = 10;
|
||||||
|
base = 2;
|
||||||
|
ex *= 4; /* We need to correct the current exponent after we change the base */
|
||||||
|
break;
|
||||||
} else if (base == 10 && (*str == 'E' || *str == 'e')) {
|
} else if (base == 10 && (*str == 'E' || *str == 'e')) {
|
||||||
foundexp = 1;
|
foundexp = 1;
|
||||||
break;
|
break;
|
||||||
@ -360,9 +368,9 @@ int janet_scan_number_base(
|
|||||||
}
|
}
|
||||||
while (str < end) {
|
while (str < end) {
|
||||||
int digit = digit_lookup[*str & 0x7F];
|
int digit = digit_lookup[*str & 0x7F];
|
||||||
if (*str > 127 || digit >= base) goto error;
|
if (*str > 127 || digit >= exp_base) goto error;
|
||||||
if (ee < (INT32_MAX / 40)) {
|
if (ee < (INT32_MAX / 40)) {
|
||||||
ee = base * ee + digit;
|
ee = exp_base * ee + digit;
|
||||||
}
|
}
|
||||||
str++;
|
str++;
|
||||||
seenadigit = 1;
|
seenadigit = 1;
|
||||||
|
@ -208,5 +208,8 @@
|
|||||||
(parser/consume p `")`)
|
(parser/consume p `")`)
|
||||||
(assert (= (parser/produce p) ["hello"]))
|
(assert (= (parser/produce p) ["hello"]))
|
||||||
|
|
||||||
|
# Hex floats
|
||||||
|
(assert (= math/pi +0x1.921fb54442d18p+0001))
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user