Repro code:
using System;
using System.Text;
class Program {
static void Main(string[] args) {
var infinity = "\u221e";
Console.OutputEncoding = Encoding.GetEncoding(1252);
Console.WriteLine(infinity);
Console.ReadLine();
}
}
Code page 1252 is a pretty common accident in England since it is the default Windows code page there. As it is for Western Europe and the Americas. Lots of reasons to change the default Console.OutputEncoding property programmatically, many text files will be encoded in 1252. Or from the command line by typing chcp 1252
(chcp == change code page) before starting the program.
As you can tell from the character set supported by 1252, the Infinity symbol is not available. So the Encoding has to come up with a substitute. That is often the ?
glyph for unsupported Unicode codepoints, the Encoding.EncoderFallback property value for 8-bit encodings. But for 1252, and the legacy MS-Dos 850 and 858 code pages, the Microsoft programmer decided for 8
. Funny guy.
The glyph is supported in the usual code page for console apps on a Western machine. Which is 437, matches the legacy IBM character set. Having these kind of encoding disasters is why Unicode was invented. Sadly too late to rescue console apps, far too much code around that relied on the default MS-Dos code page.
Having Double.PositiveInfinity converted to "∞" is specific to Win10. It used to be "Infinity" in previous Windows versions. These kind of formats can normally be modified with Control Panel > Language > Change date, time, or number formats > Additional Settings button but the infinity symbol selection is not included in the dialog. Also not covered by the registry (HKCU\Control Panel\International), rather a big oversight. It is LOCALE_SPOSINFINITY in the native winapi. In a .NET program you can override it programmatically by cloning the CultureInfo and changing its NumberFormatInfo.PositiveInfinitySymbol property. Like this:
using System;
using System.Text;
using System.Threading;
using System.Globalization;
class Program {
static void Main(string[] args) {
Console.OutputEncoding = Encoding.GetEncoding(1252);
var ci = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
ci.NumberFormat.NegativeInfinitySymbol = "-Infinity";
ci.NumberFormat.PositiveInfinitySymbol = "And beyond";
Thread.CurrentThread.CurrentCulture = ci;
Console.WriteLine(1 / 0.0);
Console.ReadLine();
}
}