53 |
|
|
54 |
=end original |
=end original |
55 |
|
|
56 |
Perl's operator overloading facility is completely ignored here. Operator |
Perl の演算子オーバーロード機能はここでは完全に無視されます。 |
57 |
overloading allows user-defined behaviors for numbers, such as operations |
演算子オーバーロードは、任意の大きさの整数、任意の精度の浮動小数点数、 |
58 |
over arbitrarily large integers, floating points numbers with arbitrary |
合同算術や p 進数算術などの「特殊な」数値の演算などの数値に関するユーザー定義の |
59 |
precision, operations over "exotic" numbers such as modular arithmetic or |
振る舞いを指定できます。 |
60 |
p-adic arithmetic, and so on. See L<overload> for details. |
詳細については L<overload> を参照してください。 |
|
(TBT) |
|
61 |
|
|
62 |
=head1 Storing numbers |
=head1 Storing numbers |
63 |
|
|
98 |
整数に対して「ネイティブな」という用語が暗示する唯一のものは、 |
整数に対して「ネイティブな」という用語が暗示する唯一のものは、 |
99 |
対応している真の整数量の最大値と最小値は 2 のべき乗に近いということです。 |
対応している真の整数量の最大値と最小値は 2 のべき乗に近いということです。 |
100 |
しかし、「ネイティブな」浮動小数点数は最も基本的な制限を持ちます: |
しかし、「ネイティブな」浮動小数点数は最も基本的な制限を持ちます: |
101 |
they may represent only those numbers which have a relatively |
2 進数分数に変換したときに相対的に「短い」表現を持つ値のみを表現できます。 |
|
"short" representation when converted to a binary fraction. |
|
102 |
例えば、0.9 はネイティブな浮動小数点では表現できません; なぜなら 0.9 の |
例えば、0.9 はネイティブな浮動小数点では表現できません; なぜなら 0.9 の |
103 |
2 進数の分数は無限となるからです: |
2 進数の分数は無限となるからです: |
104 |
|
|
141 |
|
|
142 |
=end original |
=end original |
143 |
|
|
144 |
Similarly, decimal strings can represent only those numbers which have a |
同様に、10 進文字列は有限 10 進記数法を持つ数値のみ表現できます。 |
145 |
finite decimal expansion. Being strings, and thus of arbitrary length, there |
文字列であるため、従って任意の長さを持つため、これらの数値のための |
146 |
is no practical limit for the exponent or number of decimal digits for these |
指数部や実数部には実用上の制限はありません。 |
147 |
numbers. (But realize that what we are discussing the rules for just the |
(しかし、議論しているのはこれらの数値の I<保管> に関するものであると |
148 |
I<storage> of these numbers. The fact that you can store such "large" numbers |
いうことを理解してください。 |
149 |
does not mean that the I<operations> over these numbers will use all |
このような「大きい」数値を保管できるということは、これらの数値による |
150 |
of the significant digits. |
I<操作> が全ての桁を使うということを意味しません。 |
151 |
詳細については L<"Numeric operators and numeric conversions"> を |
詳細については L<"Numeric operators and numeric conversions"> を |
152 |
参照してください。) |
参照してください。) |
|
(TBT) |
|
153 |
|
|
154 |
=begin original |
=begin original |
155 |
|
|
162 |
|
|
163 |
=end original |
=end original |
164 |
|
|
165 |
In fact numbers stored in the native integer format may be stored either |
実際のところ、ネイティブな整数形式で保管された数値は、符号付きのネイティブな |
166 |
in the signed native form, or in the unsigned native form. Thus the limits |
形式か、符号なしのネイティブな形式のどちらかで保管されます。 |
167 |
for Perl numbers stored as native integers would typically be -2**31..2**32-1, |
従って、ネイティブな整数として保管される Perl の数値の限界は、典型的には |
168 |
with appropriate modifications in the case of 64-bit integers. Again, this |
-2**31..2**32-1 で、64 ビット整数の場合は適切に修正されたものになります。 |
169 |
does not mean that Perl can do operations only over integers in this range: |
再び、これは Perl がこの幅でのみ整数を扱えるということを意味しません: |
170 |
it is possible to store many more integers in floating point format. |
浮動小数点形式によってもっと多くの整数を保管可能です。 |
|
(TBT) |
|
171 |
|
|
172 |
=begin original |
=begin original |
173 |
|
|
176 |
|
|
177 |
=end original |
=end original |
178 |
|
|
179 |
要約すると、Perl の数値は、有限 10 進拡張か、「短い」バイナリ拡張を持つ |
要約すると、Perl の数値は、有限 10 進数記法か、「短い」2 進数記法を持つ |
180 |
数値のみが格納できます。 |
数値のみが格納できます。 |
181 |
|
|
182 |
=head1 Numeric operators and numeric conversions |
=head1 Numeric operators and numeric conversions |
205 |
|
|
206 |
6 種類のこのような変換が可能です: |
6 種類のこのような変換が可能です: |
207 |
|
|
208 |
|
=begin original |
209 |
|
|
210 |
native integer --> native floating point (*) |
native integer --> native floating point (*) |
211 |
native integer --> decimal string |
native integer --> decimal string |
212 |
native floating_point --> native integer (*) |
native floating_point --> native integer (*) |
214 |
decimal string --> native integer |
decimal string --> native integer |
215 |
decimal string --> native floating point (*) |
decimal string --> native floating point (*) |
216 |
|
|
217 |
|
=end original |
218 |
|
|
219 |
|
ネイティブな整数 --> ネイティブな浮動小数点数 (*) |
220 |
|
ネイティブな整数 --> 10 進数文字列 |
221 |
|
ネイティブな浮動小数点数 --> ネイティブな整数 (*) |
222 |
|
ネイティブな浮動小数点数 --> 10 進数文字列 (*) |
223 |
|
10 進数文字列 --> ネイティブな整数 |
224 |
|
10 進数文字列 --> ネイティブな浮動小数点数 (*) |
225 |
|
|
226 |
=begin original |
=begin original |
227 |
|
|
228 |
These conversions are governed by the following general rules: |
These conversions are governed by the following general rules: |
242 |
|
|
243 |
=end original |
=end original |
244 |
|
|
245 |
If the source number can be represented in the target form, that |
変換元の数値が変換先の形式で表現できるなら、その表現が使われます。 |
|
representation is used. |
|
|
(TBT) |
|
246 |
|
|
247 |
=item * |
=item * |
248 |
|
|
253 |
|
|
254 |
=end original |
=end original |
255 |
|
|
256 |
If the source number is outside of the limits representable in the target form, |
変換元の数値が変換先の形式で表現できる限界を超えている場合、最も近い |
257 |
a representation of the closest limit is used. (I<Loss of information>) |
限界値が用いられます。 |
258 |
(TBT) |
(I<情報の欠落>) |
259 |
|
|
260 |
=item * |
=item * |
261 |
|
|
266 |
|
|
267 |
=end original |
=end original |
268 |
|
|
269 |
If the source number is between two numbers representable in the target form, |
変換元の数値が変換先の形式で表現できる二つの数値の間にある場合、 |
270 |
a representation of one of these numbers is used. (I<Loss of information>) |
二つの数値表現のどちらかが使われます。 |
271 |
(TBT) |
(I<情報の欠落>) |
272 |
|
|
273 |
=item * |
=item * |
274 |
|
|
280 |
|
|
281 |
=end original |
=end original |
282 |
|
|
283 |
In C<< native floating point --> native integer >> conversions the magnitude |
C<< ネイティブな浮動小数点数 --> ネイティブな整数 >> |
284 |
of the result is less than or equal to the magnitude of the source. |
変換で、結果の絶対値は変換元の絶対値以下となります。 |
285 |
(I<"Rounding to zero".>) |
(I<「0 への丸め」。>) |
|
(TBT) |
|
286 |
|
|
287 |
=item * |
=item * |
288 |
|
|
296 |
|
|
297 |
=end original |
=end original |
298 |
|
|
299 |
If the C<< decimal string --> native integer >> conversion cannot be done |
もし C<< 10 進数文字列 --> ネイティブな整数 >> |
300 |
without loss of information, the result is compatible with the conversion |
変換が情報の欠落なしに行えない場合、結果は |
301 |
sequence C<< decimal_string --> native_floating_point --> native_integer >>. |
C<< 10 進数文字列 --> ネイティブな浮動小数点数 --> ネイティブな整数 >> |
302 |
In particular, rounding is strongly biased to 0, though a number like |
という変換に準拠します。 |
303 |
C<"0.99999999999999999999"> has a chance of being rounded to 1. |
特に、丸めは 0 方向に強く偏っていますが、 |
304 |
(TBT) |
C<"0.99999999999999999999"> のような数が 1 に丸められる可能性はあります。 |
305 |
|
|
306 |
=back |
=back |
307 |
|
|
313 |
|
|
314 |
=end original |
=end original |
315 |
|
|
316 |
B<RESTRICTION>: The conversions marked with C<(*)> above involve steps |
B<制限>: 上記で C<(*)> マークが付いている変換は C コンパイラによって |
317 |
performed by the C compiler. In particular, bugs/features of the compiler |
行われます。 |
318 |
used may lead to breakage of some of the above rules. |
特に、使用しているコンパイラのバグ/仕様が上記のルールの一部を破ることに |
319 |
(TBT) |
なるかもしれません。 |
320 |
|
|
321 |
=head1 Flavors of Perl numeric operations |
=head1 Flavors of Perl numeric operations |
322 |
|
|
332 |
|
|
333 |
=end original |
=end original |
334 |
|
|
335 |
Perl operations which take a numeric argument treat that argument in one |
数値の引数を取る Perl の操作は、引数を 4 つの異なる方法のどれかによって |
336 |
of four different ways: they may force it to one of the integer/floating/ |
扱われます: 整数/浮動小数点数/文字列数のどれかに強制されるか、 |
337 |
string formats, or they may behave differently depending on the format of |
オペランドの形式に依存して異なる振る舞いをするかです。 |
338 |
the operand. Forcing a numeric value to a particular format does not |
特定の形式への数値の強制は、保管されている値は変更しません。 |
|
change the number stored in the value. |
|
|
(TBT) |
|
339 |
|
|
340 |
=begin original |
=begin original |
341 |
|
|
346 |
|
|
347 |
=end original |
=end original |
348 |
|
|
349 |
All the operators which need an argument in the integer format treat the |
引数として整数形式を必要とする全ての演算子は引数を合同算術として扱います; |
350 |
argument as in modular arithmetic, e.g., C<mod 2**32> on a 32-bit |
つまり、32 ビットアーキテクチャでは C<mod 2**32> です。 |
351 |
architecture. C<sprintf "%u", -1> therefore provides the same result as |
従って、C<sprintf "%u", -1> は C<sprintf "%u", ~0> と同じ結果となります。 |
|
C<sprintf "%u", ~0>. |
|
|
(TBT) |
|
352 |
|
|
353 |
=over 4 |
=over 4 |
354 |
|
|
372 |
2 項演算子 C<+> C<-> C<*> C</> C<%> C<==> C<!=> C<E<gt>> C<E<lt>> |
2 項演算子 C<+> C<-> C<*> C</> C<%> C<==> C<!=> C<E<gt>> C<E<lt>> |
373 |
C<E<gt>=> C<E<lt>=> と、単項演算子 C<-> C<abs> C<--> は引数を整数に |
C<E<gt>=> C<E<lt>=> と、単項演算子 C<-> C<abs> C<--> は引数を整数に |
374 |
変換しようとします。 |
変換しようとします。 |
375 |
If both conversions are possible |
もし両方の変換は精度を失うことなく可能で、演算が精度を失うことなく |
376 |
without loss of precision, and the operation can be performed without |
実行できるなら、整数の結果が使われます。 |
377 |
loss of precision then the integer result is used. Otherwise arguments are |
さもなければ、引数は浮動小数点数形式に変換され、浮動小数点数の結果が |
378 |
converted to floating point format and the floating point result is used. |
使われます。 |
379 |
The caching of conversions (as described above) means that the integer |
(上述したような)変換のキャッシュは、整数変換が浮動小数点数の小数部を |
380 |
conversion does not throw away fractional parts on floating point numbers. |
捨てないことを意味します。 |
|
(TBT) |
|
381 |
|
|
382 |
=item ++ |
=item ++ |
383 |
|
|
389 |
|
|
390 |
=end original |
=end original |
391 |
|
|
392 |
C<++> は上述のその他の演算子と同様に振る舞いますが、 |
C<++> は上述のその他の演算子と同様に振る舞いますが、もし文字列が |
393 |
except that if it is a string |
C</^[a-zA-Z]*[0-9]*\z/> にマッチングする形式なら、L<perlop> に記述している |
394 |
matching the format C</^[a-zA-Z]*[0-9]*\z/> the string increment described |
文字列インクリメントが使われます。 |
|
in L<perlop> is used. |
|
|
(TBT) |
|
395 |
|
|
396 |
=item Arithmetic operators during C<use integer> |
=item Arithmetic operators during C<use integer> |
397 |
|
|
398 |
|
(C<use integer> 中の算術演算子) |
399 |
|
|
400 |
=begin original |
=begin original |
401 |
|
|
402 |
In scopes where C<use integer;> is in force, nearly all the operators listed |
In scopes where C<use integer;> is in force, nearly all the operators listed |
406 |
|
|
407 |
=end original |
=end original |
408 |
|
|
409 |
In scopes where C<use integer;> is in force, nearly all the operators listed |
C<use integer;> が有効なスコープ中では、上述のほとんど全ての演算子は |
410 |
above will force their argument(s) into integer format, and return an integer |
引数を整数形式に強制し、整数の結果を返します。 |
411 |
result. The exceptions, C<abs>, C<++> and C<-->, do not change their |
例外は C<abs>, C<++>, C<--> で、C<use integer;> でも振る舞いは変わりません。 |
|
behavior with C<use integer;> |
|
|
(TBT) |
|
412 |
|
|
413 |
=item Other mathematical operators |
=item Other mathematical operators |
414 |
|
|
437 |
|
|
438 |
=item Bitwise operators during C<use integer> |
=item Bitwise operators during C<use integer> |
439 |
|
|
440 |
(C<use integer> が有効な場合のビット単位演算子) |
(C<use integer> 中のビット単位演算子) |
441 |
|
|
442 |
=begin original |
=begin original |
443 |
|
|
462 |
=end original |
=end original |
463 |
|
|
464 |
引数を整数に強制します。 |
引数を整数に強制します。 |
465 |
This is applicable |
これは例えば、C<sysread> の第 3 引数と第 4 引数に適用されます。 |
|
to the third and fourth arguments of C<sysread>, for example. |
|
|
(TBT) |
|
466 |
|
|
467 |
=item Operators which expect a string |
=item Operators which expect a string |
468 |
|
|
489 |
|
|
490 |
=end original |
=end original |
491 |
|
|
492 |
Though forcing an argument into a particular form does not change the |
引数の特定の形式への強制は保管されている数値は変更しませんが、Perl は変換の |
493 |
stored number, Perl remembers the result of such conversions. In |
結果を覚えています。 |
494 |
particular, though the first such conversion may be time-consuming, |
特に、最初の変換が時間がかかるものであったとしても、同じ操作を繰り返しても |
495 |
repeated operations will not need to redo the conversion. |
変換を再実行する必要はありません。 |
|
(TBT) |
|
496 |
|
|
497 |
=head1 AUTHOR |
=head1 AUTHOR |
498 |
|
|
508 |
|
|
509 |
=begin meta |
=begin meta |
510 |
|
|
511 |
Created: Kentaro Shirakata <argrath@ub32.org> (5.10.0-) |
Translate: Kentaro Shirakata <argrath@ub32.org> (5.10.0-) |
512 |
|
|
513 |
=end meta |
=end meta |
514 |
|
|