Skip to content

[BUG] Incorrect operations involving Inf and NaN #72

@bvadorno

Description

@bvadorno

Code of Conduct

By submitting this report you automatically agree that you've read and accepted the following conditions.

  • Support for DQ Robotics is given voluntarily and it's not the developers' role to educate and/or convince anyone of their vision.
  • Any possible response and its timeliness will be based on the relevance, accuracy, and politeness of a request and the following discussion.
  • If a DQ Robotics member replies, the user must let them know if their response solves their issue or not.
  • Any suggestion/advice/request made by anyone, as well intentioned as they might be, might not be incorporated into DQ Robotics.

Bug description

The C++ code currently doesn't handle operations between Inf/NaN and dual quaternions. This leads to incorrect results in edge cases. This is similar to the issue described in dqrobotics/matlab#117.

To Reproduce

This has been replicated by @juanjqo here: dqrobotics/matlab#117 (comment)

Code

#include <iostream>
#include <dqrobotics/DQ.h>

using namespace  DQ_robotics;

/**
 * @brief show_data shows the value of a given DQ and its coefficients
 * @param x The DQ to be shown.
 */
void show_data(const DQ& x);

int main()
{
    std::vector<DQ> list_of_problematic_operations = {
        inv(DQ(0)),
        inv(E_),
        E_*NAN,
        DQ{1}*NAN,
        E_*INFINITY,
        DQ{1}*INFINITY,
        };
    for (auto& x : list_of_problematic_operations)
        show_data(x);
    return 0;
}

void show_data(const DQ& x)
{
    std::cout<<"-----"<<std::endl;
    std::cout<<"x: "<<x<<std::endl;
    std::cout<<"x.q: "<<x.q.transpose()<<std::endl;
    std::cout<<"-----"<<std::endl;
}
CMakeLists.txt

Clone and build:

cmake_minimum_required(VERSION 3.22...3.26)

project(mbug117 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


if(UNIX AND NOT APPLE)
    FIND_PACKAGE(Eigen3 REQUIRED)
    INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIR})
    ADD_COMPILE_OPTIONS(-Werror=return-type -Wall -Wextra -Wmissing-declarations -Wredundant-decls -Woverloaded-virtual)
endif()

if(APPLE)
    INCLUDE_DIRECTORIES(
        /usr/local/include/
        /usr/local/include/eigen3
        # Most recent versions of brew install here
        /opt/homebrew/include
        /opt/homebrew/include/eigen3)
    ADD_COMPILE_OPTIONS(-Werror=return-type -Wall -Wextra -Wmissing-declarations -Wredundant-decls -Woverloaded-virtual)
    # The library is installed here when using the regular cmake ., make, sudo make install
    LINK_DIRECTORIES(
        /usr/local/lib/)
endif()

add_executable(mbug117 main.cpp)

target_link_libraries(mbug117
    dqrobotics
)

Output

-----
x: 0
x.q: -nan -nan -nan -nan -nan -nan -nan -nan
-----
-----
x: 0
x.q: -nan -nan -nan -nan -nan -nan -nan -nan
-----
-----
x: 0
x.q: nan nan nan nan nan nan nan nan
-----
-----
x: 0
x.q: nan nan nan nan nan nan nan nan
-----
-----
x: E*(inf)
x.q: -nan -nan -nan -nan  inf -nan -nan -nan
-----
-----
x: inf
x.q:  inf -nan -nan -nan -nan -nan -nan -nan
-----

Expected behavior
It must behave exactly like in MATLAB.

Expected output
Analogous to MATLAB's.

Environment:

  • OS: Ubuntu 24.04.01 LTS
  • dqrobotics version: libdqrobotics:amd64/noble 20.04.0-0-202505300421-ubuntu24.04.1
  • CPP compiler: gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

Additional context

  • This bug will be fixed after the MATLAB one is fixed.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions