[System.Numerics] Ported code from MS referencesource