本文整理汇总了C#中AType.ConvertToRestrictedWholeNumber方法的典型用法代码示例。如果您正苦于以下问题:C# AType.ConvertToRestrictedWholeNumber方法的具体用法?C# AType.ConvertToRestrictedWholeNumber怎么用?C# AType.ConvertToRestrictedWholeNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AType
的用法示例。
在下文中一共展示了AType.ConvertToRestrictedWholeNumber方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCutNumber
private int GetCutNumber(AType right, AType left)
{
if (!(left.Type == ATypes.AFloat || left.Type == ATypes.AInteger || left.Type == ATypes.ANull))
{
throw new Error.Type(this.TypeErrorText);
}
AType scalar;
int cutValue;
// get the first scalar value with length check on
if (!left.TryFirstScalar(out scalar, true))
{
throw new Error.Nonce(this.NonceErrorText);
}
// check if the scalar is a whole number and set the desired count of items
if (!left.ConvertToRestrictedWholeNumber(out cutValue))
{
throw new Error.Type(this.TypeErrorText);
}
if (right.Rank > 8)
{
throw new Error.MaxRank(MaxRankErrorText);
}
if (right.Rank == 0 && cutValue != 1)
{
throw new Error.Rank(RankErrorText);
}
return cutValue;
}
示例2: Process
protected override AType Process(AType argument)
{
int result;
if (!argument.ConvertToRestrictedWholeNumber(out result))
{
throw new Error.Type(TypeErrorText);
}
return AInteger.Create((result != 0) ? 1 : 0);
}
示例3: CalculateOr
private AType CalculateOr(AType right, AType left)
{
int a, b;
if (right.ConvertToRestrictedWholeNumber(out b) && left.ConvertToRestrictedWholeNumber(out a))
{
int result = (a != 0 || b != 0) ? 1 : 0;
return AInteger.Create(result);
}
throw new Error.Type(this.TypeErrorText);
}
示例4: ExtractExpandArgument
/// <summary>
/// Extract the byte representation from the given number, if it is correct.
/// </summary>
/// <param name="number"></param>
/// <returns>0 or 1.</returns>
private byte ExtractExpandArgument(AType number)
{
int result;
if (!number.ConvertToRestrictedWholeNumber(out result))
{
throw new Error.Type(TypeErrorText);
}
if (result != 0 && result != 1)
{
throw new Error.Domain(DomainErrorText);
}
return (byte)result;
}
示例5: PerformIndexAssign
private static void PerformIndexAssign(AType target, AType value)
{
if (target.Rank > 0)
{
for (int i = 0; i < target.Length; i++)
{
PerformIndexAssign(target[i], value.IsArray ? value[i] : value);
}
}
else
{
AValue result;
if (target.Type == value.Type)
{
result = value.Clone().Data;
}
else if (target.Type == ATypes.AInteger && value.Type == ATypes.AFloat)
{
int number;
if (!value.ConvertToRestrictedWholeNumber(out number))
{
throw new Error.Type("assign");
}
result = AInteger.Create(number).Data;
}
else if (target.Type == ATypes.AFloat && value.Type == ATypes.AInteger)
{
result = AFloat.Create(value.asInteger).Data;
}
else
{
throw new Error.Type("Assign");
}
if (target.IsMemoryMappedFile)
{
((IMapped)target.Data).Update(result);
}
else
{
target.Data = result;
}
}
}
示例6: ExtractInteger
private int ExtractInteger(AType item)
{
int element;
if (!item.ConvertToRestrictedWholeNumber(out element))
{
throw new Error.Type(TypeErrorText);
}
if (element < 0)
{
throw new Error.Domain(DomainErrorText);
}
return element;
}
示例7: ConvertToInt
/// <summary>
/// Convert argument to integer.
/// </summary>
/// <param name="argument"></param>
/// <returns></returns>
protected AType ConvertToInt(AType argument)
{
if (argument.IsArray)
{
AType result = AArray.Create(ATypes.AInteger);
foreach (AType item in argument)
{
result.AddWithNoUpdate(ConvertToInt(item));
}
result.Length = argument.Length;
result.Shape = new List<int>(argument.Shape);
result.Rank = argument.Rank;
return result;
}
else
{
int result;
if(argument.ConvertToRestrictedWholeNumber(out result))
{
return AInteger.Create(result);
}
else
{
throw new Error.Type(TypeErrorText);
}
}
}
示例8: CreatePartitionInfo
private PartitionJobInfo CreatePartitionInfo(AType right, AType left)
{
// left side type must be float, integer or null
if (left.Type != ATypes.AFloat && left.Type != ATypes.AInteger && left.Type != ATypes.ANull || left.IsBox)
{
throw new Error.Type(TypeErrorText);
}
// if the right side is scalar then we throw Rank error exception
if (right.Rank < 1)
{
throw new Error.Rank(RankErrorText);
}
int element;
List<int> partitionVector = new List<int>();
int remainder = 0;
int sum = 0;
bool going = true;
// TODO: check if this branch can be eliminated if the argument is raveled always
if (left.IsArray)
{
// TODO: Check this:
// if the left rank is higher than 1 then we ravel it to vector.
AType raveled_y = left.Rank > 1 ? MonadicFunctionInstance.Ravel.Execute(left) : left;
// get the integer list from the right side
foreach (AType item in raveled_y)
{
// if the actual item is float then we convert it to (if it's a restricted whole number)
if (!item.ConvertToRestrictedWholeNumber(out element))
{
throw new Error.Type(TypeErrorText);
}
if (element < 0)
{
// negative item raise domain error
throw new Error.Domain(DomainErrorText);
}
sum += element;
if (right.Length > 0 && going)
{
// compute how many item we can take from the list at last
if (sum > right.Length)
{
partitionVector.Add(right.Length - (sum - element));
going = false;
}
else
{
// collect the item to y list
partitionVector.Add(element);
if (sum == right.Length)
{
going = false;
}
}
}
else
{
// count the empty elements what we need
remainder++;
}
}
}
else
{
// this case is when the left side is scalar
if (!left.ConvertToRestrictedWholeNumber(out element))
{
throw new Error.Type(TypeErrorText);
}
if (element < 0)
{
throw new Error.Domain(DomainErrorText);
}
else if (element != 0)
{
int round = right.Length / element;
for (int i = 0; i < round; i++)
{
partitionVector.Add(element);
}
int rem = right.Length % element;
if (rem != 0)
{
partitionVector.Add(rem);
}
}
else
{
//.........这里部分代码省略.........