Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parse32F(sourceString) {
if (isHexLiteral(sourceString)) {
return parseHexFloat(sourceString);
}
if (isInfLiteral(sourceString)) {
return sourceString[0] === "-" ? -1 : 1;
}
if (isNanLiteral(sourceString)) {
return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x400000);
}
return parseFloat(sourceString);
}
export function parse64F(sourceString) {
if (isHexLiteral(sourceString)) {
return parseHexFloat(sourceString);
}
if (isInfLiteral(sourceString)) {
return sourceString[0] === "-" ? -1 : 1;
}
if (isNanLiteral(sourceString)) {
return (
(sourceString[0] === "-" ? -1 : 1) *
(sourceString.includes(":")
? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16)
: 0x8000000000000)
);
}
if (isHexLiteral(sourceString)) {
return parseHexFloat(sourceString);
}
return parseFloat(sourceString);
}
export function parse32F(sourceString: string): number {
if (isHexLiteral(sourceString)) {
return parseHexFloat(sourceString);
}
if (isInfLiteral(sourceString)) {
return sourceString[0] === "-" ? -1 : 1;
}
if (isNanLiteral(sourceString)) {
return (
(sourceString[0] === "-" ? -1 : 1) *
(sourceString.includes(":")
? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16)
: 0x400000)
);
}
return parseFloat(sourceString);
}
export function parse64F(sourceString) {
if (isHexLiteral(sourceString)) {
return parseHexFloat(sourceString);
}
if (isInfLiteral(sourceString)) {
return sourceString[0] === "-" ? -1 : 1;
}
if (isNanLiteral(sourceString)) {
return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x8000000000000);
}
if (isHexLiteral(sourceString)) {
return parseHexFloat(sourceString);
}
return parseFloat(sourceString);
}