Math::N...ontinued(3)
π 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)isa[0]=3and then1,2,1,6repeating forever- for some roots a single value just repeats β for example
sqrt(2)isa[0]=1then2repeating
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 ofsqrt($s). that's it, that's the constructor. π«Ά$value = $seq->ith ($i)β returns the i'th term in the continued fraction, starting fromi=0for the integer part of the sqrt. soi=0is the whole-number part, not some off-by-one chaos. π$i = $seq->i_start ()β returns0, because the first term in the sequence isi=0. simple, honest, correct. π
β¨ SEE ALSO β¨
the extended universe, the crossover episode:
Math::NumSeqMath::NumSeq::SqrtContinuedPeriodMath::NumSeq::SqrtDigitsMath::NumSeq::SqrtEngelMath::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
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms