Spark中的大整数

时间:2015-07-31 13:21:02

标签: apache-spark

在Spark-shell中,我运行以下代码:

    #define printm(p) writeToAnalyticsFile p
    void writeToAnalyticsFile (const char* format, ...)
    {
        std::string errorLog;
        std::string headerLine = "\"errorText\":";
        FILE *fp = fopen( "Analyse.txt", "w" );
        if( 0 == fp )
        {

        }
        else
        {
            va_list args;
            va_start (args, format);
            vsprintf (const_cast<char*>(errorLog.c_str()),format, args);
            va_end (args);
            fputs(headerLine.c_str(),fp);
            fputs("\"",fp);
            fputs( errorLog.c_str(), fp );
            fputs("\"",fp);

            fclose(fp);
        }
    }


    class abc
    {

    public:
        static const char *  func()
        {
            std::string str = "john";
            return str.c_str();
        }
    };


    int main()
    {

        printm(("My  Name is %s and surname is %s and age is %d",abc::func(),"john",25));
        return 0;
    }

为什么结果为2 * 1881824400 = -531318496?不是3763648800?

这是Spark中的错误吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

谢谢ccheneson和hveiga。答案是映射使结果大于2 ^ 31,超出了Interger的范围。因此,数字跳入负数区域。