=encoding euc-jp =head1 NAME =begin original perlnumber - semantics of numbers and numeric operations in Perl =end original perlnumber - Perl �Ǥο��ͤȿ������ΰ�̣�� =head1 SYNOPSIS =begin original $n = 1234; # decimal integer $n = 0b1110011; # binary integer $n = 01234; # octal integer $n = 0x1234; # hexadecimal integer $n = 12.34e-56; # exponential notation $n = "-12.34e56"; # number specified as a string $n = "1234"; # number specified as a string =end original $n = 1234; # 10 �ʿ� $n = 0b1110011; # 2 �ʿ� $n = 01234; # 8 �ʿ� $n = 0x1234; # 16 �ʿ� $n = 12.34e-56; # �ؿ�ɽ�� $n = "-12.34e56"; # ʸ���Ȥ��ƻ��ꤵ�줿���� $n = "1234"; # ʸ���Ȥ��ƻ��ꤵ�줿���� =head1 DESCRIPTION =begin original This document describes how Perl internally handles numeric values. =end original ����ʸ��ϡ�Perl �������ǿ��ͤ�ɤΤ褦�˰������򵭽Ҥ��ޤ��� =begin original Perl's operator overloading facility is completely ignored here. Operator overloading allows user-defined behaviors for numbers, such as operations over arbitrarily large integers, floating points numbers with arbitrary precision, operations over "exotic" numbers such as modular arithmetic or p-adic arithmetic, and so on. See L for details. =end original Perl �α黻�ҥ����С������ɵ�ǽ�Ϥ����Ǥϴ�����̵�뤵��ޤ��� �黻�ҥ����С������ɤϡ�Ǥ�դ��礭����������Ǥ�դ����٤���ư���������� ��Ʊ���Ѥ� p �ʿ����ѤʤɤΡ��ü�ʡ׿��ͤα黻�ʤɤο��ͤ˴ؤ���桼��������� �����񤤤����Ǥ��ޤ��� �ܺ٤ˤĤ��Ƥ� L �򻲾Ȥ��Ƥ��������� =head1 Storing numbers (���ͤ��ݴ�) =begin original Perl can internally represent numbers in 3 different ways: as native integers, as native floating point numbers, and as decimal strings. Decimal strings may have an exponential notation part, as in C<"12.34e-56">. I here means "a format supported by the C compiler which was used to build perl". =end original Perl ������Ū�˿��ͤ� 3 �Ĥΰۤʤä���ˡ��ɽ���Ǥ��ޤ�: �ͥ��ƥ��֤������� �ͥ��ƥ��֤���ư����������10 ��ʸ����Ǥ��� 10 ��ʸ����� C<"12.34e-56"> �Τ褦�˻ؿ�����������⤢��ޤ��� �����Ǥ� I<�ͥ��ƥ��֤�> �Ȥ����Τϡ���perl ��ӥ�ɤ���ݤ˻Ȥ�줿 C ����ѥ��餬�б����Ƥ�������פ��̣���ޤ��� =begin original The term "native" does not mean quite as much when we talk about native integers, as it does when native floating point numbers are involved. The only implication of the term "native" on integers is that the limits for the maximal and the minimal supported true integral quantities are close to powers of 2. However, "native" floats have a most fundamental restriction: they may represent only those numbers which have a relatively "short" representation when converted to a binary fraction. For example, 0.9 cannot be represented by a native float, since the binary fraction for 0.9 is infinite: =end original �֥ͥ��ƥ��֤ΡפȤ����Ѹ�ϥͥ��ƥ��֤������˴ؤ����ä��Ȥ��ˤϤۤȤ�� ��̣�Ϥʤ����ͥ��ƥ��֤���ư���������˴ؤ��ݤ˰�̣������ޤ��� �������Ф��ơ֥ͥ��ƥ��֤ʡפȤ����Ѹ줬�ż�����ͣ��Τ�Τϡ� �б����Ƥ��뿿�������̤κ����ͤȺǾ��ͤ� 2 �Τ٤���˶ᤤ�Ȥ������ȤǤ��� ���������֥ͥ��ƥ��֤ʡ���ư���������ϺǤ����Ū�����¤�����ޤ�: 2 �ʿ�ʬ�����Ѵ������Ȥ�������Ū�ˡ�û����ɽ��������ͤΤߤ�ɽ���Ǥ��ޤ��� �㤨�С�0.9 �ϥͥ��ƥ��֤���ư�������Ǥ�ɽ���Ǥ��ޤ���; �ʤ��ʤ� 0.9 �� 2 �ʿ���ʬ����̵�¤Ȥʤ뤫��Ǥ�: binary0.1110011001100... =begin original with the sequence C<1100> repeating again and again. In addition to this limitation, the exponent of the binary number is also restricted when it is represented as a floating point number. On typical hardware, floating point values can store numbers with up to 53 binary digits, and with binary exponents between -1024 and 1024. In decimal representation this is close to 16 decimal digits and decimal exponents in the range of -304..304. The upshot of all this is that Perl cannot store a number like 12345678901234567 as a floating point number on such architectures without loss of information. =end original C<1100> �������֤���ޤ��� �������¤ˤ��廊�ơ�2 �ʿ��λؿ��⡢��ư���������Ȥ���ɽ�������� ���¤���ޤ��� ŵ��Ū�ʥϡ��ɥ������Ǥϡ���ư���������� 53 ��ޤǤ� 2 �ʿ��ȡ� -1024 ���� 1024 �ޤǤ� 2 �ʿ��ؿ����ݴɤǤ��ޤ��� 10 ��ɽ���Ǥϡ��ۤ� 16 ��� 10 �ʿ��� -304 ���� 304 ���ϰϤλؿ��Ȥʤ�ޤ��� ��������Ƥη����ϡ����Τ褦�ʥ������ƥ�����Ǥϡ�Perl �� 12345678901234567 �Ȥ��ä��������η���ʤ�����ư���������Ȥ��� �ݴɤ��뤳�ȤϤǤ��ʤ��Ȥ������ȤǤ��� =begin original Similarly, decimal strings can represent only those numbers which have a finite decimal expansion. Being strings, and thus of arbitrary length, there is no practical limit for the exponent or number of decimal digits for these numbers. (But realize that what we are discussing the rules for just the I of these numbers. The fact that you can store such "large" numbers does not mean that the I over these numbers will use all of the significant digits. See L<"Numeric operators and numeric conversions"> for details.) =end original Ʊ�ͤˡ�10 ��ʸ�����ͭ�� 10 �ʵ���ˡ����Ŀ��ͤΤ�ɽ���Ǥ��ޤ��� ʸ����Ǥ��뤿�ᡢ���ä�Ǥ�դ�Ĺ������Ĥ��ᡢ�����ο��ͤΤ���� �ؿ�����¿����ˤϼ��Ѿ�����¤Ϥ���ޤ��� (���������������Ƥ���ΤϤ����ο��ͤ� I<�ݴ�> �˴ؤ����ΤǤ���� �������Ȥ����򤷤Ƥ��������� ���Τ褦�ʡ��礭���׿��ͤ��ݴɤǤ���Ȥ������Ȥϡ������ο��ͤˤ�� I<���> �����Ƥη��Ȥ��Ȥ������Ȥ��̣���ޤ��� �ܺ٤ˤĤ��Ƥ� L<"Numeric operators and numeric conversions"> �� ���Ȥ��Ƥ���������) =begin original In fact numbers stored in the native integer format may be stored either in the signed native form, or in the unsigned native form. Thus the limits for Perl numbers stored as native integers would typically be -2**31..2**32-1, with appropriate modifications in the case of 64-bit integers. Again, this does not mean that Perl can do operations only over integers in this range: it is possible to store many more integers in floating point format. =end original �ºݤΤȤ������ͥ��ƥ��֤������������ݴɤ��줿���ͤϡ�����դ��Υͥ��ƥ��֤� �����������ʤ��Υͥ��ƥ��֤ʷ����Τɤ��餫���ݴɤ���ޤ��� ���äơ��ͥ��ƥ��֤������Ȥ����ݴɤ���� Perl �ο��ͤθ³��ϡ�ŵ��Ū�ˤ� -2**31..2**32-1 �ǡ�64 �ӥå������ξ���Ŭ�ڤ˽������줿��Τˤʤ�ޤ��� �Ƥӡ������ Perl ���������ǤΤ������򰷤���Ȥ������Ȥ��̣���ޤ���: ��ư�����������ˤ�äƤ�ä�¿�����������ݴɲ�ǽ�Ǥ��� =begin original Summing up, Perl numeric values can store only those numbers which have a finite decimal expansion or a "short" binary expansion. =end original ���󤹤�ȡ�Perl �ο��ͤϡ�ͭ�� 10 �ʿ���ˡ������û����2 �ʿ���ˡ����� ���ͤΤߤ���Ǽ�Ǥ��ޤ��� =head1 Numeric operators and numeric conversions (���ͱ黻�Ҥȿ����Ѵ�) =begin original As mentioned earlier, Perl can store a number in any one of three formats, but most operators typically understand only one of those formats. When a numeric value is passed as an argument to such an operator, it will be converted to the format understood by the operator. =end original ���ҤΤ褦�ˡ�Perl �� 3 �Ĥη����Τɤ�Ǥ���ͤ��Ǽ�Ǥ��ޤ����� �ۤȤ�ɤα黻�Ҥ�ŵ��Ū�ˤϤ����η����ΰ�Ĥ����������򤷤ޤ��� ���ͤ����Τ褦�ʱ黻�Ҥΰ����Ȥ����Ϥ����Ȥ����黻�Ҥ�����Ǥ�������� �Ѵ�����ޤ��� =begin original Six such conversions are possible: =end original 6 ����Τ��Τ褦���Ѵ�����ǽ�Ǥ�: =begin original native integer --> native floating point (*) native integer --> decimal string native floating_point --> native integer (*) native floating_point --> decimal string (*) decimal string --> native integer decimal string --> native floating point (*) =end original �ͥ��ƥ��֤����� --> �ͥ��ƥ��֤���ư�������� (*) �ͥ��ƥ��֤����� --> 10 �ʿ�ʸ���� �ͥ��ƥ��֤���ư�������� --> �ͥ��ƥ��֤����� (*) �ͥ��ƥ��֤���ư�������� --> 10 �ʿ�ʸ���� (*) 10 �ʿ�ʸ���� --> �ͥ��ƥ��֤����� 10 �ʿ�ʸ���� --> �ͥ��ƥ��֤���ư�������� (*) =begin original These conversions are governed by the following general rules: =end original �������Ѵ��ϡ��ʲ��ΰ���Ū�ʵ�§�˽����ޤ�: =over 4 =item * =begin original If the source number can be represented in the target form, that representation is used. =end original �Ѵ����ο��ͤ��Ѵ���η�����ɽ���Ǥ���ʤ顢����ɽ�����Ȥ��ޤ��� =item * =begin original If the source number is outside of the limits representable in the target form, a representation of the closest limit is used. (I) =end original �Ѵ����ο��ͤ��Ѵ���η�����ɽ���Ǥ���³���Ķ���Ƥ����硢�Ǥ�ᤤ �³��ͤ��Ѥ����ޤ��� (I<����η���>) =item * =begin original If the source number is between two numbers representable in the target form, a representation of one of these numbers is used. (I) =end original �Ѵ����ο��ͤ��Ѵ���η�����ɽ���Ǥ�����Ĥο��ͤδ֤ˤ����硢 ��Ĥο���ɽ���Τɤ��餫���Ȥ��ޤ��� (I<����η���>) =item * =begin original In C<< native floating point --> native integer >> conversions the magnitude of the result is less than or equal to the magnitude of the source. (I<"Rounding to zero".>) =end original C<< �ͥ��ƥ��֤���ư�������� --> �ͥ��ƥ��֤����� >> �Ѵ��ǡ���̤������ͤ��Ѵ����������Ͱʲ��Ȥʤ�ޤ��� (I<��0 �ؤδݤ�ס�>) =item * =begin original If the C<< decimal string --> native integer >> conversion cannot be done without loss of information, the result is compatible with the conversion sequence C<< decimal_string --> native_floating_point --> native_integer >>. In particular, rounding is strongly biased to 0, though a number like C<"0.99999999999999999999"> has a chance of being rounded to 1. =end original �⤷ C<< 10 �ʿ�ʸ���� --> �ͥ��ƥ��֤����� >> �Ѵ�������η���ʤ��˹Ԥ��ʤ���硢��̤� C<< 10 �ʿ�ʸ���� --> �ͥ��ƥ��֤���ư�������� --> �ͥ��ƥ��֤����� >> �Ȥ����Ѵ��˽�򤷤ޤ��� �äˡ��ݤ�� 0 �����˶����ФäƤ��ޤ����� C<"0.99999999999999999999"> �Τ褦�ʿ��� 1 �˴ݤ�����ǽ���Ϥ���ޤ��� =back =begin original B: The conversions marked with C<(*)> above involve steps performed by the C compiler. In particular, bugs/features of the compiler used may lead to breakage of some of the above rules. =end original B<����>: �嵭�� C<(*)> �ޡ������դ��Ƥ����Ѵ��� C ����ѥ���ˤ�ä� �Ԥ��ޤ��� �äˡ����Ѥ��Ƥ��륳��ѥ���ΥХ�/���ͤ��嵭�Υ롼��ΰ������ˤ뤳�Ȥ� �ʤ뤫�⤷��ޤ��� =head1 Flavors of Perl numeric operations (Perl �ο��ͱ黻�Ҥ��ÿ�) =begin original Perl operations which take a numeric argument treat that argument in one of four different ways: they may force it to one of the integer/floating/ string formats, or they may behave differently depending on the format of the operand. Forcing a numeric value to a particular format does not change the number stored in the value. =end original ���ͤΰ������� Perl �����ϡ������� 4 �Ĥΰۤʤ���ˡ�Τɤ줫�ˤ�ä� �����ޤ�: ����/��ư��������/ʸ������Τɤ줫�˶�������뤫�� ���ڥ��ɤη����˰�¸���ưۤʤ뿶���񤤤򤹤뤫�Ǥ��� ����η����ؤο��ͤζ����ϡ��ݴɤ���Ƥ����ͤ��ѹ����ޤ��� =begin original All the operators which need an argument in the integer format treat the argument as in modular arithmetic, e.g., C on a 32-bit architecture. C therefore provides the same result as C. =end original �����Ȥ�������������ɬ�פȤ������Ƥα黻�Ҥϰ������Ʊ���ѤȤ��ư����ޤ�; �Ĥޤꡢ32 �ӥåȥ������ƥ�����Ǥ� C �Ǥ��� ���äơ�C �� C ��Ʊ����̤Ȥʤ�ޤ��� =over 4 =item Arithmetic operators (���ѱ黻��) =begin original The binary operators C<+> C<-> C<*> C C<%> C<==> C C> C> C=> C=> and the unary operators C<-> C and C<--> will attempt to convert arguments to integers. If both conversions are possible without loss of precision, and the operation can be performed without loss of precision then the integer result is used. Otherwise arguments are converted to floating point format and the floating point result is used. The caching of conversions (as described above) means that the integer conversion does not throw away fractional parts on floating point numbers. =end original 2 ��黻�� C<+> C<-> C<*> C C<%> C<==> C C> C> C=> C=> �ȡ�ñ��黻�� C<-> C C<--> �ϰ����������� �Ѵ����褦�Ȥ��ޤ��� �⤷ξ�����Ѵ������٤򼺤����Ȥʤ���ǽ�ǡ��黻�����٤򼺤����Ȥʤ� �¹ԤǤ���ʤ顢�����η�̤��Ȥ��ޤ��� ����ʤ���С���������ư���������������Ѵ����졢��ư���������η�̤� �Ȥ��ޤ��� (��Ҥ����褦��)�Ѵ��Υ���å���ϡ������Ѵ�����ư���������ξ������� �ΤƤʤ����Ȥ��̣���ޤ��� =item ++ =begin original C<++> behaves as the other operators above, except that if it is a string matching the format C the string increment described in L is used. =end original C<++> �Ͼ�ҤΤ���¾�α黻�Ҥ�Ʊ�ͤ˿����񤤤ޤ������⤷ʸ���� C �˥ޥå��󥰤�������ʤ顢L �˵��Ҥ��Ƥ��� ʸ���󥤥󥯥���Ȥ��Ȥ��ޤ��� =item Arithmetic operators during C (C ��λ��ѱ黻��) =begin original In scopes where C is in force, nearly all the operators listed above will force their argument(s) into integer format, and return an integer result. The exceptions, C, C<++> and C<-->, do not change their behavior with C =end original C ��ͭ���ʥ���������Ǥϡ���ҤΤۤȤ�����Ƥα黻�Ҥ� ���������������˶������������η�̤��֤��ޤ��� �㳰�� C, C<++>, C<--> �ǡ�C �Ǥ⿶���񤤤��Ѥ��ޤ��� =item Other mathematical operators (����¾�ο��ر黻��) =begin original Operators such as C<**>, C and C force arguments to floating point format. =end original C<**>, C, C �Ȥ��ä��黻�Ҥϰ�������ư���������˶������ޤ��� =item Bitwise operators (�ӥå�ñ�̱黻��) =begin original Arguments are forced into the integer format if not strings. =end original �����ϡ�ʸ����Ǥʤ���������˶�������ޤ��� =item Bitwise operators during C (C ��Υӥå�ñ�̱黻��) =begin original forces arguments to integer format. Also shift operations internally use signed integers rather than the default unsigned. =end original �����������˶������ޤ��� �ޤ������ե����ϡ��ǥե���Ȥ����ʤ������ǤϤʤ�������դ������� ����Ū�˻Ȥ��ޤ��� =item Operators which expect an integer (���������ꤷ�Ƥ���黻��) =begin original force the argument into the integer format. This is applicable to the third and fourth arguments of C, for example. =end original �����������˶������ޤ��� ������㤨�С�C ���� 3 �������� 4 ������Ŭ�Ѥ���ޤ��� =item Operators which expect a string (ʸ��������ꤷ�Ƥ���黻��) =begin original force the argument into the string format. For example, this is applicable to C. =end original ������ʸ����˶������ޤ��� �㤨�С������ C ��Ŭ�Ѥ���ޤ��� =back =begin original Though forcing an argument into a particular form does not change the stored number, Perl remembers the result of such conversions. In particular, though the first such conversion may be time-consuming, repeated operations will not need to redo the conversion. =end original ����������η����ؤζ������ݴɤ���Ƥ�����ͤ��ѹ����ޤ��󤬡�Perl ���Ѵ��� ��̤�Ф��Ƥ��ޤ��� �äˡ��ǽ���Ѵ������֤��������ΤǤ��ä��Ȥ��Ƥ⡢Ʊ�����򷫤��֤��Ƥ� �Ѵ���Ƽ¹Ԥ���ɬ�פϤ���ޤ��� =head1 AUTHOR Ilya Zakharevich C Editorial adjustments by Gurusamy Sarathy Updates for 5.8.0 by Nicholas Clark =head1 SEE ALSO L, L =begin meta Translate: SHIRAKATA Kentaro (5.10.0-) Status: completed =end meta