Why isn’t there a log base 2 function in the standard Math library?
Seems pretty essential.
…which leads to:
I found a log2 function in the Extmath lib from the RAA, but it seems
to return a Float that looks like a Fixnum:
irb(main):004:0> require ‘extmath’
=> true
irb(main):005:0> Extmath.log2 8
=> 3
irb(main):006:0> x = Extmath.log2 8
=> 3
irb(main):007:0> x.class
=> Float #if it were a float, I would expect to see 3.0 not 3 !
irb(main):008:0> x.to_i
=> 2
So Extmath.log2 8 returns 3, but it’s really a Float so it should be 3.0,
how can 3 be a Float? I’m confused, but at least now I know why my code
which was using this log2 function isn’t working.
And to add insult to injury, to_i appears to turn 3 into 2. What gives?
At Fri, 23 Apr 2004 15:54:10 +0900,
Phil Tomson wrote in [ruby-talk:98084]:
So Extmath.log2 8 returns 3, but it’s really a Float so it should be 3.0,
how can 3 be a Float? I’m confused, but at least now I know why my code
which was using this log2 function isn’t working.
It isn’t related with the issue from [ruby-talk:97891]?
At Fri, 23 Apr 2004 15:54:10 +0900,
Phil Tomson wrote in [ruby-talk:98084]:
So Extmath.log2 8 returns 3, but it’s really a Float so it should be 3.0,
how can 3 be a Float? I’m confused, but at least now I know why my code
which was using this log2 function isn’t working.
It isn’t related with the issue from [ruby-talk:97891]?
At Fri, 23 Apr 2004 15:54:10 +0900,
Phil Tomson wrote in [ruby-talk:98084]:
So Extmath.log2 8 returns 3, but it’s really a Float so it should be 3.0,
how can 3 be a Float? I’m confused, but at least now I know why my code
which was using this log2 function isn’t working.
It isn’t related with the issue from [ruby-talk:97891]?
At Fri, 23 Apr 2004 15:54:10 +0900,
Phil Tomson wrote in [ruby-talk:98084]:
So Extmath.log2 8 returns 3, but it’s really a Float so it should be 3.0,
how can 3 be a Float? I’m confused, but at least now I know why my code
which was using this log2 function isn’t working.
It isn’t related with the issue from [ruby-talk:97891]?