Questions tagged [fixnum]

The Ruby Fixnum class.

Ruby's Fixnum is an integer class that is used to hold values that fit inside a native machine integer (less 1 bit for housekeeping purposes). Fixnums are converted to Bignums as needed.

75 questions
97
votes
6 answers

Ruby max integer

I need to be able to determine a systems maximum integer in Ruby. Anybody know how, or if it's possible?
Allyn
  • 20,271
  • 16
  • 57
  • 68
22
votes
2 answers

Ruby no implicit conversion of Fixnum into String (TypeError)

I am trying to answer the following question from Chris Pine's "Learn to Program" book: Leap years. Write a program that asks for a starting year and an ending year and then puts all the leap years between them (and including them, if they are also…
stecd
  • 1,681
  • 6
  • 19
  • 28
11
votes
7 answers

Turning long fixed number to array Ruby

Is there a method in ruby to turn fixnum like 74239 into an array like [7,4,2,3,9]?
Ilya Nikiforov
  • 121
  • 1
  • 1
  • 4
9
votes
8 answers

Without Converting to a String, How Many Digits Does a Fixnum Have?

I want find the length of a Fixnum, num, without converting it into a String. In other words, how many digits are in num without calling the .to_s() method: num.to_s.length
Orcris
  • 3,135
  • 6
  • 24
  • 24
6
votes
2 answers

Negative infinity in Lisp

I'm looking for the standard way to represent negative infinity in Lisp. Is there a symblic value which is recognised by Lisp's arithmetic functions as less than all other numbers? Specifically, I'm looking for an elegant way to write the…
jforberg
  • 6,537
  • 3
  • 29
  • 47
5
votes
4 answers

Ruby On Rails - "undefined method `id' for 4:Fixnum"

I recently decided I wanted to list all the users in my Ruby On Rails application - since I couldn't figure out how to list them any other way, I decided to use partials. I have the following on my administration page (just hooked up to a its own…
user354346
5
votes
2 answers

How do I always round a number down in Ruby?

For example, if I want 987 to equal "900".
Jesse McCann
  • 55
  • 2
  • 7
5
votes
1 answer

TypeError: wrong argument type with Ruby &~ operator

I try to compare flags in my Ruby application. I have this code : if self.flag &~ flag == self.flag return false But it won't run. I've narrowed the problem to this : irb(main):020:0> my_user.flag => 1 irb(main):021:0> flag =>…
Mat
  • 952
  • 2
  • 11
  • 28
5
votes
3 answers

Why can't I divide a fixnum by another fixnum?

I'm currently trying to divide counts["email"] a hash containing the number 82,000 by a variable total which contains the value 1.3 million. When I run puts counts["email"]/total I get 0. Why can't I perform division on these?
Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151
4
votes
1 answer

Fixnum being treated as Array in Ruby

I am new to Ruby and I am trying out the merge sort algorithm as given in Wikipedia I am getting "comparison of Fixnum with Array failed (ArgumentError)" failed error when comparing the first elements of the left and right array in the merge method.…
Pramod
  • 5,150
  • 3
  • 45
  • 46
4
votes
3 answers

What is the difference between Fixnum and Numeric

They seem equivalent, but when comparing them, it's false: 5.is_a? Fixnum # => true 5.is_a? Numeric # => true Numeric == Fixnum # => false
GMarx
  • 473
  • 3
  • 13
4
votes
1 answer

Is there any elegant method in Ruby to convert a number to an array of digits

For number n, I could only think of array_of_digits = n.to_s.split('').map(&:to_i) Is there any more elegant method?
doge
  • 132
  • 1
  • 8
4
votes
2 answers

Ruby Integer and Fixnum unexpexted behavior

I want to use gcd function of the Integer class. Using the example from Ruby Doc as a test it fails: irb(main):001:0> 72.gcd 168 NoMethodError: undefined method `gcd' for 72:Fixnum from (irb):1 I have the windows one click installer ruby…
Gerhard
  • 6,850
  • 8
  • 51
  • 81
3
votes
3 answers

How to convince Lisp SBCL to do inline fixnum arithmetic?

I've found some techniques in other SO answers, but apparently I've been unable to convince SBCL to do inline fixnum arithmetic: (declaim (optimize (speed 2) (safety 1))) (declaim (ftype (function (fixnum fixnum) double-float) fixnumtest) (inline…
igouy
  • 2,547
  • 17
  • 16
3
votes
1 answer

Is Fixnum's power! method potentially dangerous?

Why is the power! method in Ruby's Fixnum class named with an exclamation mark? By convention, methods that have a name ending in an ! are potentially dangerous (for example, they may modify the instance in some way). I can appreciate the…
Jeff
  • 21,744
  • 6
  • 51
  • 55
1
2 3 4 5