Skip to content

Commit 1b1c77e

Browse files
authored
Merge pull request #150 from kdnakt/translate-cast
Translate untranslated lines in cast.md
2 parents 96e44f6 + ecdcaa7 commit 1b1c77e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/types/cast.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ fn main() {
3838
3939
// Error! There are limitations in conversion rules.
4040
// A float cannot be directly converted to a char.
41+
// エラー! 変換ルールには制限があります。
42+
// 浮動小数点数を文字に直接変換することはできません。
4143
let character = decimal as char;
4244
// FIXME ^ Comment out this line
45+
// FIXME ^ この行をコメントアウトしましょう。
4346
4447
println!("Casting: {} -> {} -> {}", decimal, integer, character);
4548
@@ -62,6 +65,7 @@ fn main() {
6265
println!(" -1 as a u8 is : {}", (-1i8) as u8);
6366
6467
// For positive numbers, this is the same as the modulus
68+
// 正の数では、これは剰余と同じです。
6569
println!("1000 mod 256 is : {}", 1000 % 256);
6670
6771
// When casting to a signed type, the (bitwise) result is the same as
@@ -72,6 +76,7 @@ fn main() {
7276
// 2. 2の補数(two's complement)をとる
7377
7478
// Unless it already fits, of course.
79+
// すでに収まっている場合はそのままです。
7580
println!(" 128 as a i16 is: {}", 128 as i16);
7681
7782
// 128 as u8 -> 128, whose value in 8-bit two's complement representation is:
@@ -90,6 +95,10 @@ fn main() {
9095
// when casting from float to int. If the floating point value exceeds
9196
// the upper bound or is less than the lower bound, the returned value
9297
// will be equal to the bound crossed.
98+
// Rust 1.45以降、浮動小数点数を整数にキャストするとき、
99+
// `as`キーワードが *飽和的キャスト* を行います。
100+
// 浮動小数点数の値が上限を超えたり下限を下回ったりする場合は、
101+
// 戻り値は越えられた境界の値となります。
93102
94103
// 300.0 as u8 is 255
95104
println!(" 300.0 as u8 is : {}", 300.0_f32 as u8);
@@ -101,6 +110,9 @@ fn main() {
101110
// This behavior incurs a small runtime cost and can be avoided
102111
// with unsafe methods, however the results might overflow and
103112
// return **unsound values**. Use these methods wisely:
113+
// この挙動は実行時にややコストがかかるため、安全でない方法で回避できます。
114+
// ただし、結果はオーバーフローしたり *不正確な値* を返す場合があります。
115+
// この方法は賢く使いましょう:
104116
unsafe {
105117
// 300.0 as u8 is 44
106118
println!(" 300.0 as u8 is : {}", 300.0_f32.to_int_unchecked::<u8>());

0 commit comments

Comments
 (0)