Lo que todo programador debería saber sobre aritmética de punto flotante
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

added code formatting to extension names

+7 -6
+7 -6
content/languages/perl.html
··· 11 11 ------------- 12 12 Perl can also store decimal numbers as strings, but the builtin arithmetic operators will convert them to integer or floating-point values to perform the operation. 13 13 14 - The Math::BigFloat extension provides an arbitrary-precision [decimal type](/formats/exact/): 14 + The <code>Math::BigFloat</code> extension provides an arbitrary-precision [decimal type](/formats/exact/): 15 15 16 16 use Math::BigFloat ':constant' 17 17 my $f = 0.1 + 0.2; # returns exactly 0.3 18 18 19 - The Number::Fraction extension provides a fraction type that overloads the arithmetic operators with [symbolic](/formats/exact/) fraction arithmetic: 19 + The <code>Number::Fraction</code> extension provides a fraction type that overloads the arithmetic operators with [symbolic](/formats/exact/) fraction arithmetic: 20 20 21 21 use Number::Fraction ':constants'; 22 22 my $f = '1/2' - '1/3'; # returns 1/6 23 23 24 - The Math::BigRat extension provides similar functionality. Its advantage is compatibility with the Math::BigInt and Math::BigFloat extensions, but it does not seem to support fraction literals. 24 + The <code>Math::BigRat</code> extension provides similar functionality. Its advantage is compatibility with the 25 + <code>Math::BigInt</code> and <code>Math::BigFloat</code> extensions, but it does not seem to support fraction literals. 25 26 26 27 How to Round 27 28 ------------ ··· 35 36 36 37 Note that this implicitly uses [round-to-even](/errors/rounding/). The variable <code>$#</code> contains the default format for printing numbers, but its use is considered deprecated. 37 38 38 - The Math::Round extension provides various functions for rounding floating-point values: 39 + The <code>Math::Round</code> extension provides various functions for rounding floating-point values: 39 40 40 41 use Math::Round qw(:all); 41 42 $result = nearest(.1, 4.567) # prints 4.6 42 43 $result = nearest(.01, 4.567) # prints 4.57 43 44 44 - The Math::BigFloat extension also supports various [rounding modes](/errors/rounding/): 45 + The <code>Math::BigFloat</code> extension also supports various [rounding modes](/errors/rounding/): 45 46 46 47 use Math::BigFloat; 47 48 my $n = Math::BigFloat->new(123.455); ··· 55 56 * [Math::Round extension](http://search.cpan.org/dist/Math-Round/Round.pm) 56 57 * [Number::Fraction extension](http://search.cpan.org/~davecross/Number-Fraction-1.13/lib/Number/Fraction.pm) 57 58 * [Math::BigRat extension](http://search.cpan.org/~flora/Math-BigRat-0.26/lib/Math/BigRat.pm) 58 - * [Math::BigFloat](http://search.cpan.org/~flora/Math-BigInt-1.95/lib/Math/BigFloat.pm) 59 + * [Math::BigFloat extension](http://search.cpan.org/~flora/Math-BigInt-1.95/lib/Math/BigFloat.pm) 59 60