36 writes to _sign
System.Runtime.Numerics (36)
System\Numerics\BigInteger.cs (36)
72
_sign
= value;
84
_sign
= (int)value;
89
_sign
= +1;
100
_sign
= (int)value;
113
_sign
= -1;
118
_sign
= +1;
139
_sign
= (int)value;
144
_sign
= +1;
169
_sign
= 0;
195
_sign
= -_sign;
205
_sign
= -_sign;
246
_sign
= sign;
275
_sign
= bits[0];
276
_sign
*= ((bits[3] & SignMask) != 0) ? -1 : +1;
310
_sign
= ((bits[3] & SignMask) != 0) ? -1 : +1;
315
_sign
= _sign < 0 ? -(int)_bits[0] : (int)_bits[0];
366
_sign
= 0;
374
_sign
= isNegative ? -1 : 0;
380
_sign
= (_sign << 8) | value[i];
387
_sign
= (_sign << 8) | value[i];
396
_sign
= +1;
486
_sign
= -(int)val[0];
495
_sign
= -1;
500
_sign
= -1;
506
_sign
= +1;
525
_sign
= sign;
556
_sign
= negative ? -(int)value[0] : (int)value[0];
566
_sign
= negative ? -1 : +1;
636
_sign
= -(int)magnitude;
642
_sign
= -1;
649
_sign
= -1;
656
_sign
= +1;
661
_sign
= (int)value[0];
675
_sign
= -1;
679
_sign
= +1;
697
_sign
= info.GetInt32("_sign");
230 references to _sign
System.Runtime.Numerics (230)
System\Number.BigInteger.cs (6)
634
TChar.CastFrom(value.
_sign
>= 0 ? '0' : (format == 'x') ? 'f' : 'F'),
676
int charsInHighByte = 9 - byte.LeadingZeroCount(value.
_sign
>= 0 ? highByte : (byte)~highByte);
722
sb.Append(TChar.CastFrom(value.
_sign
>= 0 ? '0' : '1'), digits - charsForBits);
799
spanSuccess = value.
_sign
.TryFormat(Unsafe.BitCast<Span<TChar>, Span<byte>>(destination), out charsWritten, formatSpan, info);
804
spanSuccess = value.
_sign
.TryFormat(Unsafe.BitCast<Span<TChar>, Span<char>>(destination), out charsWritten, formatSpan, info);
814
return value.
_sign
.ToString(formatString, info);
System\Numerics\BigInteger.cs (224)
42
/// <see cref="
_sign
"/> and <see cref="_bits"/> is <see langword="null"/>.
43
/// For all other values, <see cref="
_sign
"/> is +1 or -1 and the magnitude is in <see cref="_bits"/>.
50
/// everywhere <see cref="
_sign
"/> is used.
195
_sign = -
_sign
;
205
_sign = -
_sign
;
315
_sign =
_sign
< 0 ? -(int)_bits[0] : (int)_bits[0];
380
_sign = (
_sign
<< 8) | value[i];
387
_sign = (
_sign
<< 8) | value[i];
392
if (
_sign
< 0 && !isNegative)
395
_bits = [(uint)
_sign
];
399
if (
_sign
== int.MinValue)
732
info.AddValue("_sign",
_sign
);
777
return BitOperations.IsPow2(
_sign
);
780
if (
_sign
!= 1)
790
public bool IsZero =>
_sign
== 0;
792
public bool IsOne =>
_sign
== 1 && _bits is null;
794
public bool IsEven => _bits is null ? (
_sign
& 1) == 0 : (_bits[0] & 1) == 0;
796
public int Sign => (
_sign
>> 31) - (-
_sign
>> 31);
866
return new BigInteger((int)NumericsHelpers.Abs(value.
_sign
), value._bits);
902
(int q, int r) = Math.DivRem(dividend.
_sign
, divisor.
_sign
);
924
BigIntegerCalculator.Divide(dividend._bits, NumericsHelpers.Abs(divisor.
_sign
), quotient, out nuint rest);
926
remainder = dividend.
_sign
< 0 ? -(long)rest : (long)rest;
927
return new BigInteger(quotient, (dividend.
_sign
< 0) ^ (divisor.
_sign
< 0));
947
remainder = new(rest, dividend.
_sign
< 0);
948
BigInteger result = new(quotient, (dividend.
_sign
< 0) ^ (divisor.
_sign
< 0));
969
if (value.
_sign
< 0 || baseValue == 1.0D)
986
return Math.Log(value.
_sign
, baseValue);
1036
return BigIntegerCalculator.Gcd(NumericsHelpers.Abs(left.
_sign
), NumericsHelpers.Abs(right.
_sign
));
1042
return left.
_sign
!= 0
1043
? BigIntegerCalculator.Gcd(right._bits, NumericsHelpers.Abs(left.
_sign
))
1050
return right.
_sign
!= 0
1051
? BigIntegerCalculator.Gcd(left._bits, NumericsHelpers.Abs(right.
_sign
))
1120
nuint bitsResult = trivialValue && trivialExponent ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value.
_sign
), NumericsHelpers.Abs(exponent.
_sign
), NumericsHelpers.Abs(modulus.
_sign
)) :
1121
trivialValue ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value.
_sign
), exponent._bits!, NumericsHelpers.Abs(modulus.
_sign
)) :
1122
trivialExponent ? BigIntegerCalculator.Pow(value._bits!, NumericsHelpers.Abs(exponent.
_sign
), NumericsHelpers.Abs(modulus.
_sign
)) :
1123
BigIntegerCalculator.Pow(value._bits!, exponent._bits!, NumericsHelpers.Abs(modulus.
_sign
));
1125
result = value.
_sign
< 0 && !exponent.IsEven ? -(long)bitsResult : (long)bitsResult;
1135
BigIntegerCalculator.Pow(NumericsHelpers.Abs(value.
_sign
), NumericsHelpers.Abs(exponent.
_sign
), modulus._bits!, bits);
1139
BigIntegerCalculator.Pow(NumericsHelpers.Abs(value.
_sign
), exponent._bits!, modulus._bits!, bits);
1144
BigIntegerCalculator.Pow(value._bits!, NumericsHelpers.Abs(exponent.
_sign
), modulus._bits!, bits);
1151
result = new BigInteger(bits, value.
_sign
< 0 && !exponent.IsEven);
1180
if (value.
_sign
== 1)
1185
if (value.
_sign
== -1)
1190
if (value.
_sign
== 0)
1198
BigIntegerCalculator.Pow(NumericsHelpers.Abs(value.
_sign
), power, bits);
1199
result = new BigInteger(bits, value.
_sign
< 0 && (exponent & 1) != 0);
1208
result = new BigInteger(bits, value.
_sign
< 0 && (exponent & 1) != 0);
1219
return
_sign
;
1224
hash.Add(
_sign
);
1237
return
_sign
== other;
1242
if ((
_sign
^ other) < 0 || (cu = _bits.Length) > maxLimbs)
1264
if (
_sign
< 0)
1271
return (ulong)
_sign
== other;
1295
return
_sign
== other.
_sign
&& _bits.AsSpan().SequenceEqual(other._bits);
1302
return ((long)
_sign
).CompareTo(other);
1307
if ((
_sign
^ other) < 0 || (cu = _bits.Length) > maxLimbs)
1309
return
_sign
;
1326
return
_sign
* uuTmp.CompareTo(uu);
1332
if (
_sign
< 0)
1339
return ((ulong)(uint)
_sign
).CompareTo(other);
1367
if ((
_sign
^ other.
_sign
) < 0)
1370
return
_sign
< 0 ? -1 : +1;
1377
other._bits is not null ? -other.
_sign
:
1378
_sign
< other.
_sign
? -1 :
1379
_sign
> other.
_sign
? +1 :
1385
return
_sign
;
1389
return
_sign
< 0 ? -bitsResult : bitsResult;
1519
int sign =
_sign
;
1728
Debug.Assert(_bits is null ||
_sign
== 0 ? buffer.Length == 2 : buffer.Length >= _bits.Length + 1);
1734
buffer[0] = (nuint)
_sign
;
1735
highLimb = (
_sign
< 0) ? nuint.MaxValue : 0;
1741
if (
_sign
== -1)
1854
string signStr =
_sign
< 0 ? NumberFormatInfo.CurrentInfo.NegativeSign : "";
1932
return (long)left.
_sign
- right.
_sign
;
1935
return left.
_sign
< 0 != right.
_sign
< 0
1936
? Add(left._bits, left.
_sign
, right._bits, -right.
_sign
)
1937
: Subtract(left._bits, left.
_sign
, right._bits, right.
_sign
);
2010
return value.
_sign
;
2018
int sign = value.
_sign
;
2081
return value.
_sign
;
2090
if (value.
_sign
> 0)
2108
return value.
_sign
;
2131
long ll = value.
_sign
> 0 ? (long)uu : -(long)uu;
2132
if ((ll > 0 && value.
_sign
> 0) || (ll < 0 && value.
_sign
< 0))
2148
return value.
_sign
;
2179
Int128 ll = (value.
_sign
> 0) ? (Int128)uu : -(Int128)uu;
2181
if (((ll > 0) && (value.
_sign
> 0)) || ((ll < 0) && (value.
_sign
< 0)))
2208
return checked((uint)value.
_sign
);
2212
return value._bits.Length <= 1 && value.
_sign
>= 0
2223
return checked((ulong)value.
_sign
);
2228
if (len > maxLimbs || value.
_sign
< 0)
2251
return checked((UInt128)value.
_sign
);
2257
if ((len > maxLimbs) || (value.
_sign
< 0))
2484
left._bits is null && right._bits is null ? (BigInteger)(left.
_sign
& right.
_sign
) :
2500
? (BigInteger)(left.
_sign
| right.
_sign
)
2506
? (BigInteger)(left.
_sign
^ right.
_sign
)
2522
int zLen = (left.
_sign
< 0 || right.
_sign
< 0)
2555
left._bits, left.
_sign
,
2556
right._bits, right.
_sign
,
2587
return LeftShift(value.
_sign
, digitShift, smallShift);
2621
return new BigInteger(value.
_sign
, z);
2689
return new BigInteger(value.
_sign
>> smallShift, null);
2700
return new BigInteger(value.
_sign
>> 31, null);
2710
bool neg = value.
_sign
< 0;
2734
return ~value.
_sign
; // implicit int -> BigInteger handles int.MinValue
2739
if (value.
_sign
>= 0)
2762
public static BigInteger operator -(BigInteger value) => new BigInteger(-value.
_sign
, value._bits);
2770
return (long)value.
_sign
+ 1;
2775
if (value.
_sign
>= 0)
2800
return (long)value.
_sign
- 1;
2805
if (value.
_sign
>= 0)
2830
return (long)left.
_sign
+ right.
_sign
;
2833
return left.
_sign
< 0 != right.
_sign
< 0
2834
? Subtract(left._bits, left.
_sign
, right._bits, -right.
_sign
)
2835
: Add(left._bits, left.
_sign
, right._bits, right.
_sign
);
2840
? (BigInteger)((long)left.
_sign
* right.
_sign
)
2841
: Multiply(left._bits, left.
_sign
, right._bits, right.
_sign
);
2905
return dividend.
_sign
/ divisor.
_sign
;
2923
BigIntegerCalculator.Divide(dividend._bits, NumericsHelpers.Abs(divisor.
_sign
), quotient);
2925
BigInteger result = new BigInteger(quotient, (dividend.
_sign
< 0) ^ (divisor.
_sign
< 0));
2944
BigInteger result = new(quotient, (dividend.
_sign
< 0) ^ (divisor.
_sign
< 0));
2959
return dividend.
_sign
% divisor.
_sign
;
2972
nuint remainder = BigIntegerCalculator.Remainder(dividend._bits, NumericsHelpers.Abs(divisor.
_sign
));
2973
return dividend.
_sign
< 0 ? -(long)remainder : (long)remainder;
2987
BigInteger result = new(bits, dividend.
_sign
< 0);
3075
int sign =
_sign
;
3115
Debug.Assert(
_sign
is 1 or -1);
3128
Debug.Assert(
_sign
> int.MinValue);
3156
return uint.Log10((uint)value.
_sign
);
3185
return nint.LeadingZeroCount(value.
_sign
);
3191
return (value.
_sign
>= 0)
3201
return nint.PopCount(value.
_sign
);
3206
if (value.
_sign
>= 0)
3256
bool neg = value.
_sign
< 0;
3260
nuint rs = BitOperations.RotateLeft((nuint)value.
_sign
, rotateAmount);
3277
bool neg = value.
_sign
< 0;
3281
nuint rs = BitOperations.RotateRight((nuint)value.
_sign
, rotateAmount);
3348
return nint.TrailingZeroCount(value.
_sign
);
3390
int value =
_sign
;
3397
if (
_sign
>= 0)
3434
BinaryPrimitives.WriteIntPtrBigEndian(destination,
_sign
);
3436
else if (
_sign
>= 0)
3512
BinaryPrimitives.WriteIntPtrLittleEndian(destination,
_sign
);
3514
else if (
_sign
>= 0)
3588
if (
_sign
< 0)
3631
? (BigInteger)((BigIntegerCalculator.BitsPerLimb - 1) ^ BitOperations.LeadingZeroCount((nuint)value.
_sign
| 1))
3675
nint currentSign = value.
_sign
;
3682
nint targetSign = sign.
_sign
;
3702
? value.
_sign
> 0 ? 1
3703
: (value.
_sign
< 0 ? -1 : 0) : value.
_sign
;
3780
? (value.
_sign
& 1) == 0
3802
return value.
_sign
< 0;
3815
? (value.
_sign
& 1) != 0
3822
return value.
_sign
>= 0;
3837
return value.
_sign
== 0;
4371
actualResult = (value.
_sign
>= byte.MaxValue) ? byte.MaxValue :
4372
(value.
_sign
<= byte.MinValue) ? byte.MinValue : (byte)value.
_sign
;
4388
actualResult = (value.
_sign
>= char.MaxValue) ? char.MaxValue :
4389
(value.
_sign
<= char.MinValue) ? char.MinValue : (char)value.
_sign
;
4430
actualResult = (value.
_sign
>= short.MaxValue) ? short.MaxValue :
4431
(value.
_sign
<= short.MinValue) ? short.MinValue : (short)value.
_sign
;
4447
actualResult = (value.
_sign
>= int.MaxValue) ? int.MaxValue :
4448
(value.
_sign
<= int.MinValue) ? int.MinValue : value.
_sign
;
4491
actualResult = (value.
_sign
>= sbyte.MaxValue) ? sbyte.MaxValue :
4492
(value.
_sign
<= sbyte.MinValue) ? sbyte.MinValue : (sbyte)value.
_sign
;
4514
actualResult = (value.
_sign
>= ushort.MaxValue) ? ushort.MaxValue :
4515
(value.
_sign
<= ushort.MinValue) ? ushort.MinValue : (ushort)value.
_sign
;
4577
actualResult = (byte)value.
_sign
;
4600
actualResult = (char)value.
_sign
;
4641
actualResult = (short)value.
_sign
;
4657
actualResult = value.
_sign
;
4697
actualResult = value.
_sign
;
4754
actualResult = (Int128)(long)value.
_sign
;
4777
actualResult = value.
_sign
;
4799
actualResult = (sbyte)value.
_sign
;
4828
actualResult = (ushort)value.
_sign
;
4851
actualResult = (uint)value.
_sign
;
4891
actualResult = (ulong)value.
_sign
;
4948
actualResult = (UInt128)(Int128)(long)value.
_sign
;
4971
actualResult = (nuint)value.
_sign
;
5024
return new BigInteger((nint)value.
_sign
>>> smallShift);
5038
bool neg = value.
_sign
< 0;
5125
return new BigInteger(value.
_sign
>> 31, null);