| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks for this - but it doesn't seem to address the issue at hand. Given:
```go
func TestIssue71245(t *testing.T) {
f := math.SmallestNonzeroFloat64
s := strconv.FormatFloat(f, 'e', 25, 64)
fmt.Printf(" f = %s\n", s)
bf := NewFloat(f)
bs := bf.Text('e', 25)
fmt.Printf("bf = %s\n", bs)
fmt.Println()
s = strconv.FormatFloat(f, 'g', -1, 64)
fmt.Printf(" f = %s\n", s)
bs = bf.Text('g', -1)
fmt.Printf("bf = %s\n", bs)
}
```I get
```
$ go test -run Issue71245
f = 4.9406564584124654417656879e-324
bf = 4.9406564584124654417656879e-324
f = 5e-324
bf = 4.940656458412465e-324
```
yet I would have expected that the 2nd pair should also match (per the issue).
What am I missing?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
An aside, `strconv.FormatFloat` formats correctly ([playground](https://go.dev/play/p/YOTQR9Rvaic?v=gotip)).
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks for this - but it doesn't seem to address the issue at hand. Given:
```go
func TestIssue71245(t *testing.T) {
f := math.SmallestNonzeroFloat64
s := strconv.FormatFloat(f, 'e', 25, 64)
fmt.Printf(" f = %s\n", s)bf := NewFloat(f)
bs := bf.Text('e', 25)
fmt.Printf("bf = %s\n", bs)fmt.Println()s = strconv.FormatFloat(f, 'g', -1, 64)
fmt.Printf(" f = %s\n", s)bs = bf.Text('g', -1)
fmt.Printf("bf = %s\n", bs)
}
```I get
```
$ go test -run Issue71245
f = 4.9406564584124654417656879e-324
bf = 4.9406564584124654417656879e-324f = 5e-324
bf = 4.940656458412465e-324
```yet I would have expected that the 2nd pair should also match (per the issue).
What am I missing?
You're not missing anything.
This CL was mis-scoped; apologies.
I conflated the normal/denormal test cases
in this change set as relating to #71245
when they do not.
This CL is not addressing #71245.
Your CL 792040 added:
```
// Note that Text may return a different result than strconv.FormatFloat for
// corresponding arguments if the matching float32 or float64 number provided
// to strconv.FormatFloat is a denormalized number.
```
Given your investigation and doc string,
it seems to imply this behavior in the normals
is not WAI? https://go.dev/play/p/l3aqWjhQa0g
This is what this CL aims to address.
If this is the case, I should rewrite to something that looks like:
```
l := lower.at(i)
u := upper.at(i)
okdown := l != m || inclusive && i+1 == len(lower.mant)
okup := m != u && (inclusive || m+1 < u || i+1 < len(upper.mant) || I >= len(upper.mant) && m < '9')
```
Am I missing something?
func TestIssue71245(t *testing.T) {todo: rework; needs normals only... call them out explicitly. delink issue.
```
func TestRoundShortestNormal(t *testing.T) {
for _, x := range []float64{
4.3749999999999917e+17,
4.9999999999999917e+17,
4.7619047619047597e+17,
3.7499999999999917e+17,
1.9047619047619039e+18,
} {
want := strconv.FormatFloat(x, 'g', -1, 64)
got := new(Float).SetPrec(53).SetFloat64(x).Text('g', -1)
if got != want {
t.Errorf("Text('g', -1) = %s, want %s", got, want)
}
}
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
No, you're correct that there is indeed an issue here, per your playground example.
I filed #80206 to track this.
I have verified that `|| i >= len(upper.mant) && m < '9'` fixes this, but I need to spend some more time to understand this code again.
I suggest keeping it to this minimal fix plus adjusted comments, explaining the extra clause, in the style that's already present. (Don't add all the constants - it's not making is simpler.)
// TODO(gri) strconv/ftoa.do describes a shortcut in some cases.I believe this comment is not up-to-date - I haven't found the respective shortcut. I believe the respective code has changed a lot.
Also, in any case, it should be internal/strconv/ftoa.go now.
Maybe remove unless you can find the reference?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
done - minimal.
more details in https://github.com/golang/go/issues/80206#issuecomment-4846021933
todo: rework; needs normals only... call them out explicitly. delink issue.
```
func TestRoundShortestNormal(t *testing.T) {
for _, x := range []float64{
4.3749999999999917e+17,
4.9999999999999917e+17,
4.7619047619047597e+17,
3.7499999999999917e+17,
1.9047619047619039e+18,
} {
want := strconv.FormatFloat(x, 'g', -1, 64)
got := new(Float).SetPrec(53).SetFloat64(x).Text('g', -1)
if got != want {
t.Errorf("Text('g', -1) = %s, want %s", got, want)
}
}
}
```
Done
// TODO(gri) strconv/ftoa.do describes a shortcut in some cases.I believe this comment is not up-to-date - I haven't found the respective shortcut. I believe the respective code has changed a lot.
Also, in any case, it should be internal/strconv/ftoa.go now.
Maybe remove unless you can find the reference?
Looks like you're right: b2a346bbd1 moves it to internal/strconv/ftoa.go
also updated header of this file
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Minor suggestions.
Still working on understanding the change.
text := func(x float64) string {add a comment somewhere, perhaps on line 388:
// see go.dev/issue/80206
(this will help another reader understand why this test is here)
// m == '9' (which would carry onto the exclusive upper bound). i >= len(upper.mant) && m < '9')no need for the line break - we have big screens
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
add a comment somewhere, perhaps on line 388:
// see go.dev/issue/80206
(this will help another reader understand why this test is here)
Done
// m == '9' (which would carry onto the exclusive upper bound).add comment:
// See also go.dev/issue/80206.
Done
no need for the line break - we have big screens
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
Thanks. I think it looks right.
I've been trying to see if line 231 in roundShortest can be simplified somehow, but computing a different u upfront (rather than 0 when we are at the end), but I don't think the code would be simpler.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thanks. I think it looks right.
I've been trying to see if line 231 in roundShortest can be simplified somehow, but computing a different u upfront (rather than 0 when we are at the end), but I don't think the code would be simpler.
I do not believe you can simplify L231; CL 779340 sidesteps this entirely, though not _simple._
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |