SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    finding whether a number is rational

    I need to find whether a number is rational or not in javascript.

    could somebody help?

  2. #2
    SitePoint Enthusiast sceptik's Avatar
    Join Date
    Sep 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd take a look at the number one google search for "rational number javascript" which is a port to JS of some PHP code
    http://satchamo.com/blog/coding/fractions-javascript

  3. #3
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The link just shows addition of fractions and not determining whether a number is rational.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by mrithula View Post
    The link just shows addition of fractions and not determining whether a number is rational.
    Did you know that anything that is able to be represented as a fraction, is a rational number?
    Also, that computers can not store irrational numbers as actual numbers.

    So, you'll need to pick what range of denominator you are willing to use as a maximum size for a rational number, and then determine whether any possible denominator results in an integer nominator.

    Good luck with your assignment there.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •