Replies: 9 comments 67 replies
-
IEEE754 standard says that it has sign. .NET BCL is conforming the standard.
The answer should be no. We won't change a standard-conform behaviour to non conformant. |
Beta Was this translation helpful? Give feedback.
-
The fix is as you describe, to either create your own extension method/custom format provider that normalizes to For example: public static string ToNormalizedString1(this double value)
{
if (value == -0.0)
{
value = 0.0;
}
return value.ToString();
}
public static string ToNormalizedString2(this double value)
{
return value.ToString("0.####;-0.####;0");
} The first extension method will check for zero and normalize to positive zero. The second extension method uses the section separator to print positive/negative values with up to 4 fractional digits, if present, and zero as
Not at this time. CC @jeffhandley
There will always be people that prefer the old behavior and other people that prefer the new behavior. Ultimately, the spec defines negative zero to exist and to be formatted as
|
Beta Was this translation helpful? Give feedback.
-
we're not planning to change the behavior again due to reasons stated
above. We
want to make it as easy as possible to move code from .NET Framework to
.NET Core. Many customers find no code changes are required but in a few
cases they will need code changes due to an intentional breaking change.
If you're not considering a rollback there's no point in discussing it any
further, I am afraid. Anyway, none of what has been said until now is a
'reason', which is what pisses off the most.
Can you say more about the challenge you have using one of the
workarounds?
We were aware of the suggested workarounds already, what I am interested
here is in preserving the original behaviour. To give you an idea, we are
working on a 2M SLOC project, with about 20k unit and integration tests.
Most of them are now broken, to be inspected one by one.
Il giorno mer 23 giu 2021 alle ore 16:59 Dan Moseley <
***@***.***> ha scritto:
… @marcocecchiscmgroup <https://github.com/marcocecchiscmgroup> we're not
planning to change the behavior again due to reasons stated above. We want
to make it as easy as possible to move code from .NET Framework to .NET
Core. Many customers find no code changes are required but in a few cases
they will need code changes due to an intentional breaking change.
Can you say more about the challenge you have using one of the workarounds?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#54537 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUPWTM45UACB3KKWBUUMCD3TUHZFPANCNFSM47DGYLMQ>
.
--
HMI ENGINEER
RIMINI TECHNOLOGIC UNIT - TECHNICAL DEPARTMENT
--
|
Beta Was this translation helpful? Give feedback.
-
What you could do in case is providing a way to set the default
IFormatProvider off-band.
Il 24/06/2021 00:23, Dan Moseley ha scritto:
I wonder whether it would help to have an analyzer that flagged calls to
|ToString()| on certain types (eg., floating point types, but perhaps
all built in numeric types) where there was no format specifier. It
would be pretty noisy though. You'd only switch it on to help do a pass,
I think.
@stephentoub <https://github.com/stephentoub> thoughts about all this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<
or unsubscribe
<
.
Il giorno gio 24 giu 2021 alle ore 05:59 Stephen Toub <
***@***.***> ha scritto:
… That would be unbelievably noisy, as you suggest, to the point where I
don't think it'd be worthwhile in our adding something like that to the
SDK. Even if you wanted to do an audit and use such a rule as part of it,
I'm not sure it'd yield a meaningfully better experience than just
searching for ".ToString()".
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#54537 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUPWTM3QD4LOH6HDSRAXBUDTUKUSBANCNFSM47DGYLMQ>
.
--
HMI ENGINEER
RIMINI TECHNOLOGIC UNIT - TECHNICAL DEPARTMENT
--
|
Beta Was this translation helpful? Give feedback.
-
My suggestion was to expose a SetFormatProvider(IFormatProvider) in
IFormattable.
ToString() always uses the default format provider (which now has changed,
i.e. the 'infamous -0.00' one for doubles), but it can be overridden once
and for all, in case.
IFormattable
Il 24/06/2021 15:59, Joe4evr ha scritto:
@danmoseley <https://github.com/danmoseley> CA1305
<
already exists and ships in-box (tho it's opt-in by having to set the
Severity to warn or error).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<
or unsubscribe
<
.
Il giorno gio 24 giu 2021 alle ore 16:03 Joe4evr ***@***.***>
ha scritto:
… D'oh. Yes, that probably would be far to noisy.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#54537 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUPWTM3XDZM6SPFZWFSBWWLTUM3LVANCNFSM47DGYLMQ>
.
--
HMI ENGINEER
RIMINI TECHNOLOGIC UNIT - TECHNICAL DEPARTMENT
--
|
Beta Was this translation helpful? Give feedback.
-
I guess you wanted to mention myself.
Those uses cases are easily explained as follows. Say we have many
computations that end up writing a CNC formalism or an autoCAD dxf, IGES,
STEP, etc. We have a whole load of them. The baseline files encode tested
situations/fixed behaviours and stuff. They must not be changed, as they
represent the core of our business logic. Some date back to long ago, were
generated with various software etc. Whenever we run the tests we read some
input, re-do the calculations, regenerate the output files and compare them
to the baseline.
So can you see now? When you come down to numbers, you're messing with all
this, it is not just about breaking the compilation. In fact, you all seem
to miss this, if you think that this is just a senseless argument. This is
not about changing a signature, breaking an interface or so and I have no
memory of a compatibility break of such a high reach and impact in any
language, but of course my experience might be limited. Otherwise I
wouldn't have protested.
The fix that I suggested preserves the semantics, has a good design and
fits well with the big picture. I see no reason why it should not be
considered.
Il giorno sab 26 giu 2021 alle ore 01:15 Niclas Olofsson <
***@***.***> ha scritto:
… @marcelaldecoa <https://github.com/marcelaldecoa> if you have most of
your 20k unit tests failing because of this, I totally feel your pain. I’m
trying to decide if I agree or not, but I have a real hard time
understanding your use case where you have 20k unit tests that rely on
string comparison of calculated floating point numbers where most of them
are rounded to -0.. Would you mind elaborating around the use case this hit
for you?
Or are you simply arguing around a principle saying that .NET can not ever
introduce breaking changes to fix what Microsoft and the community perceive
as bugs?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#54537 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUPWTM5YAVPCOTU5KQOFAVDTUUEXHANCNFSM47DGYLMQ>
.
--
HMI ENGINEER
RIMINI TECHNOLOGIC UNIT - TECHNICAL DEPARTMENT
--
|
Beta Was this translation helpful? Give feedback.
-
Now that you made me think of it, I think I have found a non workaroundable
use case (in the 'your workaround' meaning).
Say we use a third-party nuget library to write dxf or whatever files. Of
course we cannot fix the ToString() in there. This is unfortunately a
show-stopper for everyone, not for us only as we couldn't upgrade and stick
with the .NET framework version, that we'll need to ship forever. My
suggestion works ok in this respect, btw.
Il giorno sab 26 giu 2021 alle ore 15:16 Marco Cecchi <
***@***.***> ha scritto:
… I guess you wanted to mention myself.
Those uses cases are easily explained as follows. Say we have many
computations that end up writing a CNC formalism or an autoCAD dxf, IGES,
STEP, etc. We have a whole load of them. The baseline files encode tested
situations/fixed behaviours and stuff. They must not be changed, as they
represent the core of our business logic. Some date back to long ago, were
generated with various software etc. Whenever we run the tests we read some
input, re-do the calculations, regenerate the output files and compare them
to the baseline.
So can you see now? When you come down to numbers, you're messing with all
this, it is not just about breaking the compilation. In fact, you all seem
to miss this, if you think that this is just a senseless argument. This is
not about changing a signature, breaking an interface or so and I have no
memory of a compatibility break of such a high reach and impact in any
language, but of course my experience might be limited. Otherwise I
wouldn't have protested.
The fix that I suggested preserves the semantics, has a good design and
fits well with the big picture. I see no reason why it should not be
considered.
Il giorno sab 26 giu 2021 alle ore 01:15 Niclas Olofsson <
***@***.***> ha scritto:
> @marcelaldecoa <https://github.com/marcelaldecoa> if you have most of
> your 20k unit tests failing because of this, I totally feel your pain. I’m
> trying to decide if I agree or not, but I have a real hard time
> understanding your use case where you have 20k unit tests that rely on
> string comparison of calculated floating point numbers where most of them
> are rounded to -0.. Would you mind elaborating around the use case this hit
> for you?
>
> Or are you simply arguing around a principle saying that .NET can not
> ever introduce breaking changes to fix what Microsoft and the community
> perceive as bugs?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#54537 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AUPWTM5YAVPCOTU5KQOFAVDTUUEXHANCNFSM47DGYLMQ>
> .
>
--
HMI ENGINEER
RIMINI TECHNOLOGIC UNIT - TECHNICAL DEPARTMENT
--
HMI ENGINEER
RIMINI TECHNOLOGIC UNIT - TECHNICAL DEPARTMENT
--
|
Beta Was this translation helpful? Give feedback.
-
The floating-point formatting/parsing logic had a lot more fixes than just
-0.0 but the others don't seem to be impacting you or aren't being raised
here.
For example, as detailed in the blog post (
https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/),
Math.PI.ToString() used to return "3.14159265358979" and now returns
"3.1415926535897931" because they are fundamentally different values
How many "patriot’s bug" have you been reported over your career? The
reason for what you describe is quite clear to me, nonetheless what I
reported are facts and I am afraid you will experience how impacting is
this over time.
There would be no good default implementation that could be provided for
this proposed API,
Global overrides are also typically bad
I don't understand to what extent a functional, unworkaroundable break you
can fly over, while an interface change is something you can’t get away
with. I guess this is somewhat aside from your own former ‘apology of
breaks’. Anyway the default implementation would be what's currently
defaulted in the latest version.
So, I think we need to move on and deal with this, one way or another, as
it we’ve got a definite answer already. This is becoming like playing the
Don Quixote, which I don’t want to.
Il giorno sab 26 giu 2021 alle ore 16:46 Tanner Gooding <
***@***.***> ha scritto:
… Exposing new methods in an interface is a binary breaking change unless
they use the newer DIMs feature and provide a default implementation.
There would be no good default implementation that could be provided for
this proposed API, the required state to manage it could not be easily
implemented by various primitive types. Global overrides are also typically
bad due to it allowing a consumer to impact a library in a way that it
wasn't tested or setup to handle.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#54537 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUPWTMZ5ALGRBSS7BWQYCNTTUXR5XANCNFSM47DGYLMQ>
.
--
HMI ENGINEER
RIMINI TECHNOLOGIC UNIT - TECHNICAL DEPARTMENT
--
|
Beta Was this translation helpful? Give feedback.
-
Go explain that to an end user... ToString() is used to present a value, with a formatting option. Except for scientists, computer enthusiasts and other respectable mathematicians, a user does not want to see -0.0 when a value is zero, and forgive me, they don't give a damn about the IEEExxxx standard. I totally respect this point of view, but ToString() has been around long enough that it should be allowed to do what it was designed to do: format a number for a user for as many use cases as possible. If we now have to be subtle because of the IEEE standard, we should instead have proposed a specific formatter, and not touch the default behavior, even if that disconcerts a minority of purists. There you go, that was my two cents. I'm going to have to review my entire UI. THANK YOU. |
Beta Was this translation helpful? Give feedback.
-
I am porting a .NET Framework 4.7.2 Visual Studio project to .NET5.0 and I am experiencing a different behaviour of double.ToString when the value is negative and close to zero.
For example, the double value -7.1054273576010019E-15 when converted to string returns "-0" even if I round it before the conversion while with the .NET Framework 4.7.2 its result was "0" (same code).
This difference is discussed here https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/ but I don't really agree that this is an improvement as the title states, I believe 0 should not have a sign, it is neither a positive number nor a negative number.
I know I can create a custom IFormatProvider or an extension method and convert the double as I want but this requires a change in every conversion in the code and also any developers working on the project will need to use it in the future. In my opionion this solution is not very intuitive and it's likely to be source of errors.
Is there a way to restore the previous behaviour with less effort? Is Microsoft willing to change this in the future versions of the .NET?
Beta Was this translation helpful? Give feedback.
All reactions