Skip to content

Commit 6c2914f

Browse files
authored
Merge pull request #2995 from maxhaton/fix_float
First pass at bringing float.dd up to scratch
2 parents 1231163 + 8515ea3 commit 6c2914f

File tree

1 file changed

+21
-47
lines changed

1 file changed

+21
-47
lines changed

spec/float.dd

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
Ddoc
22

3-
$(SPEC_S Floating Point,
3+
$(SPEC_S Floating-Point,
44

55
$(HEADERNAV_TOC)
66

7-
$(H2 $(LNAME2 fp_intermediate_values, Floating Point Intermediate Values))
7+
$(H2 $(LNAME2 fp_intermediate_values, Floating-Point Intermediate Values))
88

9-
$(P On many computers, greater
10-
precision operations do not take any longer than lesser
11-
precision operations, so it makes numerical sense to use
12-
the greatest precision available for internal temporaries.
13-
The philosophy is not to dumb down the language to the lowest
14-
common hardware denominator, but to enable the exploitation
15-
of the best capabilities of target hardware.
16-
)
17-
18-
$(P For floating point operations and expression intermediate values,
9+
$(P For floating-point operations and expression intermediate values,
1910
a greater precision can be used than the type of the
2011
expression.
2112
Only the minimum precision is set by the types of the
@@ -26,31 +17,17 @@ $(H2 $(LNAME2 fp_intermediate_values, Floating Point Intermediate Values))
2617
implemented by the hardware.
2718
)
2819

29-
$(P It's possible that, due to greater use of temporaries and
30-
common subexpressions, optimized code may produce a more
31-
accurate answer than unoptimized code.
32-
)
33-
34-
$(P Algorithms should be written to work based on the minimum
35-
precision of the calculation. They should not degrade or
36-
fail if the actual precision is greater. Float or double types,
37-
as opposed to the real (extended) type, should only be used for:
38-
)
39-
40-
$(UL
41-
$(LI reducing memory consumption for large arrays)
42-
$(LI when speed is more important than accuracy)
43-
$(LI data and function argument compatibility with C)
44-
)
20+
$(P Execution of floating-point expressions may yield a result of greater precision than dictated
21+
by the source.)
4522

46-
$(H2 $(LNAME2 fp_const_folding, Floating Point Constant Folding))
23+
$(H2 $(LNAME2 fp_const_folding, Floating-Point Constant Folding))
4724

48-
$(P Regardless of the type of the operands, floating point
25+
$(P Regardless of the type of the operands, floating-point
4926
constant folding is done in $(D real) or greater precision.
50-
It is always done following IEEE 754 rules and round-to-nearest
27+
It is always done following $(LINK2 https://standards.ieee.org/standard/754-2019.html, IEEE-754) rules and round-to-nearest
5128
is used.)
5229

53-
$(P Floating point constants are internally represented in
30+
$(P Floating-point constants are internally represented in
5431
the implementation in at least $(D real) precision, regardless
5532
of the constant's type. The extra precision is available for
5633
constant folding. Committing to the precision of the result is
@@ -67,8 +44,8 @@ writeln(f - 0.2);
6744
static float f = 0.2f;
6845
writeln(f - 0.2);
6946
---
70-
$(P will print 2.98023e-09. Hex floating point constants can also
71-
be used when specific floating point bit patterns are needed that
47+
$(P will print 2.98023e-09. Hex floating-point constants can also
48+
be used when specific floating-point bit patterns are needed that
7249
are unaffected by rounding. To find the hex value of 0.2f:)
7350

7451
---
@@ -90,12 +67,12 @@ writeln(f - 0.2);
9067

9168
$(P Different compiler settings, optimization settings,
9269
and inlining settings can affect opportunities for constant
93-
folding, therefore the results of floating point calculations may differ
70+
folding, therefore the results of floating-point calculations may differ
9471
depending on those settings.)
9572

9673
$(H2 $(LNAME2 rounding_control, Rounding Control))
9774

98-
$(P IEEE 754 floating point arithmetic includes the ability to set 4
75+
$(P IEEE 754 floating-point arithmetic includes the ability to set 4
9976
different rounding modes.
10077
These are accessible via the functions in $(D core.stdc.fenv).
10178
)
@@ -107,9 +84,9 @@ $(H2 $(LNAME2 rounding_control, Rounding Control))
10784
)
10885

10986

110-
$(H2 $(LNAME2 esception_flags, Exception Flags))
87+
$(H2 $(LNAME2 exception_flags, Exception Flags))
11188

112-
$(P IEEE 754 floating point arithmetic can set several flags based on what
89+
$(P IEEE 754 floating-point arithmetic can set several flags based on what
11390
happened with a
11491
computation:)
11592

@@ -124,22 +101,19 @@ $(H2 $(LNAME2 esception_flags, Exception Flags))
124101

125102
$(P These flags can be set/reset via the functions in $(D core.stdc.fenv).)
126103

127-
$(H2 $(LNAME2 floating-point-transformations, Floating Point Transformations))
104+
$(H2 $(LNAME2 floating-point-transformations, Floating-Point Transformations))
128105

129106
$(P An implementation may perform transformations on
130-
floating point computations in order to reduce their strength,
131-
i.e. their runtime computation time.
132-
Because floating point math does not precisely follow mathematical
133-
rules, some transformations are not valid, even though some
134-
other programming languages still allow them.
107+
floating-point computations in order to reduce their strength.
135108
)
136109

137-
$(P The following transformations of floating point expressions
110+
$(P Not all transformations are valid: The following
111+
transformations of floating-point expressions
138112
are not allowed because under IEEE rules they could produce
139113
different results.
140114
)
141115

142-
$(TABLE2 Disallowed Floating Point Transformations,
116+
$(TABLE2 Disallowed Floating-Point Transformations,
143117
$(THEAD transformation, comments)
144118
$(TROW
145119
$(ARGS $(I x) + 0 $(RARR) $(I x)) , $(ARGS not valid if $(I x) is -0)
@@ -186,4 +160,4 @@ $(SPEC_SUBNAV_PREV_NEXT garbage, Garbage Collection, iasm, D x86 Inline Assemble
186160

187161
Macros:
188162
CHAPTER=29
189-
TITLE=Floating Point
163+
TITLE=Floating-Point

0 commit comments

Comments
 (0)