相关疑难解决方法(0)

为什么"dtoa.c"包含这么多代码?

我将是第一个承认我对低级编程的整体知识有点稀疏的人.我理解许多核心概念,但我不会定期使用它们.话虽如此,我对dtoa.c需要多少代码感到非常震惊.

在过去的几个月里,我一直在使用C#进行ECMAScript实现,而且我一直在减慢填充引擎中的漏洞.昨晚我开始研究Number.prototype.toString,它在ECMAScript规范(pdf)的15.7.4.2节中描述.在第9.8.1节中,注3提供了到dtoa.c的链接,但我正在寻找挑战,所以我等待查看它.以下是我提出的建议.

private IDynamic ToString(Engine engine, Args args)
{
    var thisBinding = engine.Context.ThisBinding;
    if (!(thisBinding is NumberObject) && !(thisBinding is NumberPrimitive))
    {
        throw RuntimeError.TypeError("The current 'this' must be a number or a number object.");
    }

    var num = thisBinding.ToNumberPrimitive();

    if (double.IsNaN(num))
    {
        return new StringPrimitive("NaN");
    }
    else if (double.IsPositiveInfinity(num))
    {
        return new StringPrimitive("Infinity");
    }
    else if (double.IsNegativeInfinity(num))
    {
        return new StringPrimitive("-Infinity");
    }

    var radix = !args[0].IsUndefined ? args[0].ToNumberPrimitive().Value …
Run Code Online (Sandbox Code Playgroud)

javascript c c# floating-point ecma262

19
推荐指数
3
解决办法
1万
查看次数

标签 统计

c ×1

c# ×1

ecma262 ×1

floating-point ×1

javascript ×1