Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 340809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:39:02+00:00 2026-05-12T10:39:02+00:00

this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html , the home of rubyinline, adding/moding as indicated in

  • 0

this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html, the “home” of rubyinline, adding/moding as indicated in the comments

require 'rubygems' #added this, doesn't run otherwise
require 'inline'
class MyTest

  def factorial(n)
    f = 1
    n.downto(2) { |x| f *= x }
    f
  end

  inline do |builder|
    builder.c "
    long factorial_c(int max) {
      int i=max, result=1;
      while (i >= 2) { result *= i--; }
      return result;
    }"
  end
end

#t = MyTest.new()  # removed this
#factorial_5 = t.factorial(5) # removed this

asdf = MyTest.new # added this
puts "ruby native factorial: " + asdf.factorial(16).to_s # added this
puts "inline factorial: " + asdf.factorial_c(16).to_s # added this

when I run it, I get

ruby testfact.rb

ruby native factorial: 20922789888000

inline factorial: 2004189184

the ruby version is correct; I don’t know what the inline version is (other than incorrect).

I’m running ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]; I installed rubyinline like this: sudo gem install RubyInline

I tried changing the “int”‘s to “long”‘s in the C code, but it didn’t make a diff. (I’m not a C programmer, if that wasn’t already apparent.)

Finally, I noticed that if I run them both with 12 or less as the argument, they both yield the same answer. Things get weird at 13 and above.

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:39:03+00:00Added an answer on May 12, 2026 at 10:39 am

    In the version of C you have is a long 32 bits or 64 bits? A long is not always larger than an int in C.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 176k
  • Answers 176k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I feel your pain. I used the docs to produce… May 12, 2026 at 3:12 pm
  • Editorial Team
    Editorial Team added an answer I don't know if this solves your problem, but the… May 12, 2026 at 3:12 pm
  • Editorial Team
    Editorial Team added an answer In OS 3.x, there's a property called "zoomScale" that will… May 12, 2026 at 3:12 pm

Related Questions

Code is as follows but I get a ytplayer is not defined error. Is
There are clearly a number of packages in R for all sorts of spatial
I want to redirect all requests for index.html|php|php5 to http://www.domain.co.uk/ using mod_rewrite and I've
I would like to use the FFTW C library from Delphi 2009 and according

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.