How comes that Complex value here? (Well, require “complex” isn’t
mentioned
anywhere and it’s not an accident. This is a virgin irb session, the
Complex
lib isn’t loaded.)
When I type _.class as the next line, I get Complex. But Complex isn’t
loaded
at all. If I type in require ‘complex’, I get the answer: true. That
means, the
Complex class was just loaded, right after the things happening above.
Please forgive the brevity/spelling errors.
This message is being sent from my iPhone
To contact me by phone please
Call
Office.: 1-212-702-4027
Mobil 1-917-653-7887
Fax (Secure Fax, no cover letter needed) 1-917-265-4744
This email may contains private and confidential information.
Unauthorized use of private and confidential information is prohibited.
Thanks, that makes sense. However, that is just one half of what I
don’t
quite get:
irb(main):001:0> x, y = -0.4505495340698077, 2.718281828459045
=> [-0.4505495340698077, 2.718281828459045]
irb(main):002:0> x ** y
=> (-0.07250262422001937+0.08861014593587692i)
irb(main):003:0> -0.4505495340698077 ** y
=> -0.11449187080996949
irb(main):004:0> -0.4505495340698077 == x
=> true
How is it that the same operation gives different answer if I use a
variable containing the value-0.4505495340698077 and if I use the
number -0.4505495340698077 directly?
Look at the difference:
irb(main):010:0> -0.07250262422001937 ** y
=> -0.0007982156578935224
irb(main):011:0> (-0.07250262422001937) ** y
=> (-0.0005054745763290495+0.0006177731696920454i)
irb(main):012:0>
Ivan
"complex" and "rational" are already in core in newer versions
--
Posted via http://www.ruby-forum.com/.