| ... | @@ -729,8 +729,13 @@ fn divide(a: i32, b: i32) i32 { | ... | @@ -729,8 +729,13 @@ fn divide(a: i32, b: i32) i32 { |
| 729 | </ul> | 729 | </ul> |
| 730 | {#header_open|Float Literals#} | 730 | {#header_open|Float Literals#} |
| 731 | <p> | 731 | <p> |
| 732 | Float literals have type {#syntax#}comptime_float{#endsyntax#} which is guaranteed to hold at least all possible values | 732 | Float literals have type {#syntax#}comptime_float{#endsyntax#} which is guaranteed to have |
| 733 | that the largest other floating point type can hold. Float literals {#link|implicitly cast|Implicit Casts#} to any other type. | 733 | the same precision and operations of the largest other floating point type, which is |
| | 734 | {#syntax#}f128{#endsyntax#}. |
| | 735 | </p> |
| | 736 | <p> |
| | 737 | Float literals {#link|implicitly cast|Implicit Casts#} to any floating point type, |
| | 738 | and to any {#link|integer|Integers#} type when there is no fractional component. |
| 734 | </p> | 739 | </p> |
| 735 | {#code_begin|syntax#} | 740 | {#code_begin|syntax#} |
| 736 | const floating_point = 123.0E+77; | 741 | const floating_point = 123.0E+77; |
| ... | @@ -740,6 +745,17 @@ const yet_another = 123.0e+77; | ... | @@ -740,6 +745,17 @@ const yet_another = 123.0e+77; |
| 740 | const hex_floating_point = 0x103.70p-5; | 745 | const hex_floating_point = 0x103.70p-5; |
| 741 | const another_hex_float = 0x103.70; | 746 | const another_hex_float = 0x103.70; |
| 742 | const yet_another_hex_float = 0x103.70P-5; | 747 | const yet_another_hex_float = 0x103.70P-5; |
| | 748 | {#code_end#} |
| | 749 | <p> |
| | 750 | There is no syntax for NaN, infinity, or negative infinity. For these special values, |
| | 751 | one must use the standard library: |
| | 752 | </p> |
| | 753 | {#code_begin|syntax#} |
| | 754 | const std = @import("std"); |
| | 755 | |
| | 756 | const inf = std.math.inf(f32); |
| | 757 | const negative_inf = -std.math.inf(f64); |
| | 758 | const nan = std.math.nan(f128); |
| 743 | {#code_end#} | 759 | {#code_end#} |
| 744 | {#header_close#} | 760 | {#header_close#} |
| 745 | {#header_open|Floating Point Operations#} | 761 | {#header_open|Floating Point Operations#} |