Math::N...ontinued(3)

πŸ“¦
version 75 Β· 2 versions
, in fedora 43

πŸ’– Math::NumSeq::SqrtContinued(3) πŸ’–

okay bestie, sit down, hydrate, because we're about to read a Perl manual page together and it's genuinely about to be the most fun you've had with a continued fraction all week. this one is from the User Contributed Perl Documentation situation, and it's serving square roots in the cutest way possible. no cap. 🌸


✨ NAME ✨

Math::NumSeq::SqrtContinued β€” continued fraction expansion of a square root. it's giving math but make it a sequence. πŸ¦‹


✨ SYNOPSIS ✨

the little taste test, the trailer before the movie:

use Math::NumSeq::SqrtContinued;
my $seq = Math::NumSeq::SqrtContinued->new (sqrt => 2);
my ($i, $value) = $seq->next;

literally three lines and you're already living in sqrt(2) land. πŸ’…


✨ DESCRIPTION ✨

so here's the whole vibe: this module gives you the terms in the continued fraction expansion of a square root. it sneaks up on the root like this:

                  1
sqrt(S) = a[0] + -----------
                a[1] +   1
                       -----------
                       a[2] +   1
                              ----------
                              a[3] + ...

that's the shape of it. a nested little staircase of fractions, and honestly? iconic. πŸͺœβœ¨

the first term a[0] is just the integer part of the root. what's left over is a remainder 0 < r < 1, and that remainder gets rewritten as r=1/R where R > 1:

                 1
sqrt(S) = a[0] + ---
                 R

then a[1] is the integer part of that R, and we just keep doing it recursively. it's turtles all the way down, except the turtles are fractions. πŸ’πŸ’œ

here's the juicy part: the values from a[1] onward are always a fixed-period repeating sequence. always. every single time. periodt. 😌

  • sqrt(14) is a[0]=3 and then 1,2,1,6 repeating forever
  • for some roots a single value just repeats β€” for example sqrt(2) is a[0]=1 then 2 repeating

and if you only want the length of the period and not the whole parade of terms, go see SqrtContinuedPeriod. she's the short version. πŸŽ€


✨ FUNCTIONS ✨

peep "FUNCTIONS" in Math::NumSeq for the behaviour that all the sequence classes share, because this one is part of a whole friend group.

  • $seq = Math::NumSeq::SqrtContinued->new (sqrt => $s) β€” creates and hands you back a brand new sequence object that gives you the continued expansion terms of sqrt($s). that's it, that's the constructor. 🫢
  • $value = $seq->ith ($i) β€” returns the i'th term in the continued fraction, starting from i=0 for the integer part of the sqrt. so i=0 is the whole-number part, not some off-by-one chaos. πŸ™ˆ
  • $i = $seq->i_start () β€” returns 0, because the first term in the sequence is i=0. simple, honest, correct. πŸ‘‘

✨ SEE ALSO ✨

the extended universe, the crossover episode:

  • Math::NumSeq
  • Math::NumSeq::SqrtContinuedPeriod
  • Math::NumSeq::SqrtDigits
  • Math::NumSeq::SqrtEngel
  • Math::ContinuedFraction

go read them, they're all friends here. 🌈


✨ HOME PAGE ✨

<http://user42.tuxfamily.org/math-numseq/index.html>

the mothership. go say hi. πŸ πŸ’–


✨ LICENSE ✨

okay legal bestie moment, but make it cute:

Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde

Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.

⚠️ real talk for a sec: that "WITHOUT ANY WARRANTY" bit is not a joke, it's the actual license text, so don't come for Kevin if your sqrt misbehaves. fr fr.

aaaand that's the whole page, you made it, I'm so proud of you πŸ₯ΉπŸ’

this adorable little read was brought to you by perl v5.42.0, dated 2025-07-25, and the manual page Math::N...ontinued(3) (yes that's the truncated header, the full name got shy and cut off, we still love her). mwah, bye bestie! πŸ’‹πŸŒΈβœ¨

πŸ“¦ where this page comes from