Jump to content


- - - - -

how do you find the n'th digit in a quotient of division


4 replies to this topic

#1 paul0n0n

    Member

  • Members
  • PipPip
  • 37 posts

Posted 31 August 2009 - 03:13 AM

How do you do it?
Here is an example of what I mean.
q = "0.2893798172383982716"
other then doing long division how do you find, say, 7 in q. Or rather is there a formula for finding, if n = 5 the outcome would then be 3 in q. or if n = 13 the outcome would be 8.

why would i want to do this? just cause, i guess, asking and looking at things.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5344 posts
  • LocationSanta Clara, CA

Posted 31 August 2009 - 05:41 AM

Well, you know how to do long division, don't you? Just start dividing and keep going until you get to the desired digit.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 alphadog

    DevMaster Staff

  • Moderators
  • 1716 posts

Posted 31 August 2009 - 07:20 PM

Depends on how far in you want to go. Reedbeta's idea is KISS for low n's. But, if you want mathematical formula (cuz it's getz the chicks, right? Right!?!) a fancy way to get it is that the nth digit of a/b is the 1st digit of (10^(n-1)a mod :)/b, a.k.a. floor(10 * (10^(n-1)a mod B) / B) mod 10.
Hyperbole is, like, the absolute best, most wonderful thing ever! However, you'd be an idiot to not think dogmatism is always bad.

#4 paul0n0n

    Member

  • Members
  • PipPip
  • 37 posts

Posted 01 September 2009 - 02:32 AM

That is what I was looking for. And yes it gets chicks!

#5 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 07 September 2009 - 11:20 AM

Convert to a string and then just index it :)

I can't imagine any situation where this would actually be a performance bottleneck.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users