| ... | ... | @@ -729,8 +729,13 @@ fn divide(a: i32, b: i32) i32 { |
| 729 | 729 | </ul> |
| 730 | 730 | {#header_open|Float Literals#} |
| 731 | 731 | <p> |
| 732 | | Float literals have type {#syntax#}comptime_float{#endsyntax#} which is guaranteed to hold at least all possible values |
| 733 | | that the largest other floating point type can hold. Float literals {#link|implicitly cast|Implicit Casts#} to any other type. |
| 732 | Float literals have type {#syntax#}comptime_float{#endsyntax#} which is guaranteed to have |
| 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 | 739 | </p> |
| 735 | 740 | {#code_begin|syntax#} |
| 736 | 741 | const floating_point = 123.0E+77; |
| ... | ... | @@ -740,6 +745,17 @@ const yet_another = 123.0e+77; |
| 740 | 745 | const hex_floating_point = 0x103.70p-5; |
| 741 | 746 | const another_hex_float = 0x103.70; |
| 742 | 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 | 759 | {#code_end#} |
| 744 | 760 | {#header_close#} |
| 745 | 761 | {#header_open|Floating Point Operations#} |