Order of operations question in Ruby -


I am starting an example of a class that tests the similarities of two formulas.

The calculation value of the formula is actually the same:

  RubyKeyem :: Chemical.N.NEW ("SOOS"). Fw = & gt; 96.0 RubyChem :: Chemical.new ("OSSO"). FW = 96.0  

When I created a new square to test the similarities of these two instances, I was surprised at the results:

  x = RubyKeym :: BalanceCam.New ("SOOS", "OSSO") x.balanced = & gt; False y = RubyKeym :: BalanceCam.New ("SOOS", "SOOS") Y.balanced = & gt; True  

RubyKeym :: BalanceJam Initialisation method is here:

  Def start (Formula 1, Formula 2) @balanced = RubyChem :: Chemical.Nn ( Formula1) .fw == RubyKeyem :: Chemical.N.N (Formula2) .fw &  

Why not Ruby assumes FW for Formula 1 and Formula 2 and similarity of those values Checks? What is the order of operations in Ruby and what is Ruby doing? I can see that I lack the understanding of this issue. How can I make this work? Thank you in advance.

You probably do not want to see the floating point number of equality, instead you should compare the deltas .

Try it in irb:

  x = 1.000001 y = 1.0 x == y (x-y) .bbs < 0.00001  

Therefore, you find a delta like 0.00001 that you think floating point will handle any difference in arithmetic and use it in this way. You should never do == floats.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -