我有一个函数应该将 X 舍入到最接近的 A 倍数。
这是 JavaScript 中的代码:
var round = function (x, a) {
"use strict";
if (typeof a === "undefined") {
return Math.round(x);
}
var half = a / 2,
sign = this.sign(x),
absolute = Math.abs(x),
factor = absolute / a|0,
remainder = absolute % a;
return sign * a * (factor + (remainder < half ? 0 : 1));
};
当我--trace_deopt --code_comments
在 Chrome 的 V8 中执行操作时,我在日志中收到此消息:
[deoptimizing (DEOPT eager): begin 0x988464b35b1 round (opt #13) @13, FP to SP delta: 24]
591 ;;; deoptimize at <0:70499> tagged-to-i: not a heap number
592 translating round => node=67, height=48
593 0x7fff571f2ed0: [top + 96] <- 0x11b5fb674cf9 ; rdi 0x11b5fb674cf9 <JS Object>
594 0x7fff571f2ec8: [top + 88] <- 0x2459b11f1d89 ; r8 0x2459b11f1d89 <Number: 45>
595 0x7fff571f2ec0: [top + 80] <- 0x2d00000000 ; [sp + 40] 45
596 0x7fff571f2eb8: [top + 72] <- 0xbef1cdacfe5 ; caller's pc
597 0x7fff571f2eb0: [top + 64] <- 0x7fff571f3090 ; caller's fp
598 0x7fff571f2ea8: [top + 56] <- 0x11b5fb674d61 ; [sp + 0] 0x11b5fb674d61 <FixedArray[133]>
599 0x7fff571f2ea8: [top + 56] <- 0x11b5fb674d61; context
600 0x7fff571f2ea0: [top + 48] <- 0x988464b35b1; function
601 0x7fff571f2e98: [top + 40] <- 22 ; rcx (smi)
602 0x7fff571f2e90: [top + 32] <- 0x34565d404121 <undefined> ; literal
603 0x7fff571f2e88: [top + 24] <- 0x34565d404121 <undefined> ; literal
604 0x7fff571f2e80: [top + 16] <- 0x34565d404121 <undefined> ; literal
605 0x7fff571f2e78: [top + 8] <- 0x34565d404121 <undefined> ; literal
606 0x7fff571f2e70: [top + 0] <- 1 ; rsi (smi)
607 [deoptimizing (eager): end 0x988464b35b1 round @13 => node=67, pc=0xbef1cd97be6, state=TOS_REG, alignment=no padding, took 0.084 ms]
608 [removing optimized code for: round]
609 [evicting entry from optimizing code map (notify deoptimized) for 0x34565d492be1 <SharedFunctionInfo round>]
有谁知道是什么tagged-to-i: not a heap number
意思?
提前致谢!