logstash-plugins / logstash-filter-math

This plugin provides the ability to do various simple math operations (addition, subtraction, multiplication and division) on document fields
Apache License 2.0
1 stars 8 forks source link

Discuss: NaN and Infinity as results #4

Open guyboertje opened 6 years ago

guyboertje commented 6 years ago

The current specs assert that a result is Infinity but the JSON spec forbids them.

Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

    describe "two huge numbers should multiply to infinity" do
      sample( "var1" => 1.79769313486232e+300,  "var2" => 1e+300 ) do
        expect( subject.get("result") ).to eq( Float::INFINITY )
      end
    end

How should we validate results of Float::INFINITY and Float::NAN before we set the result into the event?

jakelandis commented 6 years ago

My 2 cents... I think Float::INFINITY and Float::NAN should be handled as error conditions. Adding two extremely large numbers will always a be a number and never reach infinity.

I would argue that Ruby is wrong here if you can get get anything other a then a number or error out of the 4 basic math functions (with discrete numbers as input).