Get double as integer

For example I have Real32 DataBuffer. If I call getInt64,what will happen? Truncate or error?

If a Real64/Double DataBuffer, I also call getInt64(). What will happen?

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @ming.cheng

    I checked and found that DataBuffer::getDouble() works with Real and Double. Otherwise, you will get the following exception.

    Invalid DataBuffer type [4] in DataBuffer::getDouble(). Only RealEnum or DoubleEnum types are allowed.

    I can call getInt() for Real but I only get the integer part.

    case DataBuffer::RealEnum:
    _out->out("\n GetInt for Real: %lld\n", dataBuffer.getInt());
    _out->out("\n GetDouble for Real: %f\n", dataBuffer.getDouble());
    printf("\nGetAsString(): %s\n", dataBuffer.getAsString().c_str());
    break;


    GetInt for Real: 3
    GetDouble for Real: 3.720099
    GetAsString(): 3.720099

Answers

  • Integer type of DataBuffer but getAsDouble(), what will happen. Basically my application's receiving variable can be a different type. For example I could getDouble() then cast the value into integer. Just want to explore whether I can call getInt64() directly. Same for all Integral DataBuffer, may I call getDouble()?

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @ming.cheng

    Thanks for reaching out to us.

    I checked the document and found that "The getInt64 method has been [DEPRECATED]. The setInt and getInt methods provide a simpler interface and can be used to replace the setInt64 and getInt64 methods."

    However, the document states that it can throw InvalidUsageException when Illegal DataBuffer Type found.

    I recommended checking the type before calling associated methods.

    I hope that this information is of help.

  • So when come to type handling, must be apple to apple, pear to pear. Otherwise user will get InvalidUsageException error. If necessary, user should convert a value to another type by user code.

  • but for Real64Enum/Real32Enum databuffer, user can still use getDouble() as normal double value?

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @ming.cheng

    According to the question, it looks like you are developing a new application with RFA C++.

    RFA C++ is a legacy API and we don't recommend developing a new application with the legacy API.

    If you are developing a new application to consume real-time data, please consider using the RTSDK C/C++ (EMA C++) instead. Please also refer to the API Compatibility Matrix for the support operating systems and compilers.

  • I am adding new feature to existing program. Thanks for reminding.