简体   繁体   English

楼层函数返回EXC_BAD_ACCESS

[英]Floor function returning EXC_BAD_ACCESS

The cod that I am using contains these snippets of code. 我正在使用的鳕鱼包含这些代码片段。 I am calling ThetaG_JD with the argument 2455343.50000 which is just a sample Julian date. 我正在用参数2455343.50000调用ThetaG_JD,这只是一个儒略日期。 Every time I run the program, I receive a EXC_BAD_ACCESS on the indicated line. 每次我运行该程序时,都会在指示的行上收到EXC_BAD_ACCESS。 When using gdb and printing out the intermediary values and passing them through the floor function, I get no error, but when Frac() is used it always returns an error. 当使用gdb并打印中间值并将它们通过floor函数传递时,我没有收到任何错误,但是当使用Frac()时,它总是返回错误。

double Frac(double arg)
{
    /* Returns fractional part of double argument */
    return arg - floor(arg);
}

double ThetaG_JD(double jd)
{
    /* Reference:  The 1992 Astronomical Almanac, page B6. */

    double UT=0, TU=0, GMST=0;
    //THIS LINE
    UT=Frac(jd+0.5);
    // THAT ONE ^^
    jd=jd-UT;
    TU=(jd-2451545.0)/36525;
    GMST=24110.54841+TU*(8640184.812866+TU*(0.093104-TU*6.2E-6));
    GMST=Modulus(GMST+secday*omega_E*UT,secday);

    return (twopi*GMST/secday);
}

The EXC_BAD_ACCESS is somewhat puzzling to me, but this sounds suspiciously like a floating point exception. EXC_BAD_ACCESS使我有些困惑,但这听起来像是一个浮点异常。 It's been a while, but as I recall on x87 hardware, you could generate overflow/underflow/NaN and the processor wouldn't let you know with an exception until the next FP operation which could be in a totally different part of the code. 已经有一段时间了,但是正如我在x87硬件上所回顾的那样,您可能会生成上溢/下溢/ NaN,并且直到下一个 FP操作(可能在代码的完全不同的部分)之前,处理器都不会让您知道。 You could try something like jd += 0.5 instead of the call for Frac and see if it still dies. 您可以尝试使用jd += 0.5来代替对Frac的调用,看看它是否仍然消失。

Also the x87 status register will be able to show you if there's an error state and you should be able to see that within gbd. 而且x87状态寄存器将能够显示是否存在错误状态,并且您应该能够在gbd中看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM