本文整理汇总了C#中Rational.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Rational.ToString方法的具体用法?C# Rational.ToString怎么用?C# Rational.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rational
的用法示例。
在下文中一共展示了Rational.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNumeral
/// <summary>
/// Returns the Z3 term corresponding to the MSF rational number.
/// </summary>
/// <param name="rational">The MSF rational</param>
/// <returns>The Z3 term</returns>
public static ArithExpr GetNumeral(Context context, Rational rational, Sort sort = null)
{
try
{
sort = rational.IsInteger() ? ((Sort)context.IntSort) : (sort == null ? (Sort)context.RealSort : sort);
return (ArithExpr)context.MkNumeral(rational.ToString(), sort);
}
catch (Z3Exception e)
{
Console.Error.WriteLine("Conversion of {0} failed:\n {1}", rational, e);
throw new NotSupportedException();
}
}
示例2: ValueNode
public ValueNode(Rational<long> value)
{
Value = value;
Name = Value.ToString();
}
示例3: buildDB
/// <summary>
///
/// </summary>
private void buildDB(System.Drawing.Imaging.PropertyItem[] parr)
{
properties.Clear();
//
data = "";
//
Encoding ascii = Encoding.ASCII;
//
foreach( System.Drawing.Imaging.PropertyItem p in parr )
{
string v = "";
string name = (string)myHash[p.Id];
// tag not found. skip it
if( name == null ) continue;
//
data += name+": ";
//
//1 = BYTE An 8-bit unsigned integer.,
if( p.Type == 0x1 )
{
v = p.Value[0].ToString();
}
//2 = ASCII An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.,
else if( p.Type == 0x2 )
{
// string
v = ascii.GetString(p.Value);
}
//3 = SHORT A 16-bit (2 -byte) unsigned integer,
else if( p.Type == 0x3 )
{
// orientation // lookup table
switch( p.Id )
{
case 0x8827: // ISO
v = "ISO-" + convertToInt16U(p.Value).ToString();
break;
case 0xA217: // sensing method
{
switch( convertToInt16U(p.Value) )
{
case 1: v = "Not defined"; break;
case 2: v = "One-chip color area sensor"; break;
case 3: v = "Two-chip color area sensor"; break;
case 4: v = "Three-chip color area sensor"; break;
case 5: v = "Color sequential area sensor"; break;
case 7: v = "Trilinear sensor"; break;
case 8: v = "Color sequential linear sensor"; break;
default: v =" reserved"; break;
}
}
break;
case 0x8822: // aperture
switch( convertToInt16U(p.Value) )
{
case 0: v = "Not defined"; break;
case 1: v = "Manual"; break;
case 2: v = "Normal program"; break;
case 3: v = "Aperture priority"; break;
case 4: v = "Shutter priority"; break;
case 5: v = "Creative program (biased toward depth of field)"; break;
case 6: v = "Action program (biased toward fast shutter speed)"; break;
case 7: v = "Portrait mode (for closeup photos with the background out of focus)"; break;
case 8: v = "Landscape mode (for landscape photos with the background in focus)"; break;
default: v = "reserved"; break;
}
break;
case 0x9207: // metering mode
switch( convertToInt16U(p.Value) )
{
case 0: v = "unknown";break;
case 1: v = "Average";break;
case 2: v = "CenterWeightedAverage"; break;
case 3: v = "Spot"; break;
case 4: v = "MultiSpot"; break;
case 5: v = "Pattern"; break;
case 6: v = "Partial"; break;
case 255: v = "Other"; break;
default: v = "reserved"; break;
}
break;
case 0x9208: // light source
{
switch(convertToInt16U(p.Value) )
{
case 0:v = "unknown";break;
case 1:v = "Daylight";break;
case 2:v = "Fluorescent";break;
case 3:v = "Tungsten";break;
case 17:v = "Standard light A";break;
case 18:v = "Standard light B";break;
case 19:v = "Standard light C";break;
case 20:v = "D55";break;
case 21:v = "D65";break;
case 22:v = "D75";break;
case 255:v = "other";break;
default:v = "reserved";break;
//.........这里部分代码省略.........
示例4: Read
/// <summary>
/// Read all <see cref="System.Drawing.Imaging.PropertyItem"/>s from the specified
/// <paramref name="jpegFilePath"/> and translate them to a dictionary containing all possible
/// EXIF properties and their respective values. When a value is not set for the specified
/// image, an empty string is provided.
/// </summary>
/// <param name="jpegFilePath">The path to an existing Jpeg file.</param>
/// <exception cref="System.ArgumentException">Thrown when the specified <paramref name="jpegFilePath"/>
/// does not point to an existing, valid Jpeg file.</exception>
public static Dictionary<string, string> Read(string jpegFilePath)
{
var propertyItems = new List<PropertyItem>();
var exifProperties = new ExifProperties();
var jpegProperties = new Dictionary<string, string>();
foreach (string exifProperty in exifProperties.Values)
jpegProperties.Add(exifProperty, string.Empty);
using (FileStream stream = new FileStream(jpegFilePath, FileMode.Open, FileAccess.Read))
{
Image image = System.Drawing.Image.FromStream(stream, true, false);
propertyItems.AddRange(image.PropertyItems);
}
foreach (var property in propertyItems)
{
if (!exifProperties.ContainsKey(property.Id)) continue;
string propertyName = exifProperties[property.Id];
string propertyValue = string.Empty;
if (property.Type == 0x1)
{
propertyValue = property.Value[0].ToString().TrimEnd('\0');
}
else if (property.Type == 0x2)
{
// 2 = ASCII
// An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with null.
propertyValue = Encoding.ASCII.GetString(property.Value).TrimEnd('\0');
}
else if (property.Type == 0x3)
{
// 3 = unsigned short
switch (property.Id)
{
case 0x8827: // ISO
propertyValue = "ISO-" + ConvertToUInt16(property.Value).ToString();
break;
case 0xA217: // sensing method
{
switch (ConvertToUInt16(property.Value))
{
case 1: propertyValue = "Not defined"; break;
case 2: propertyValue = "One-chip color area sensor"; break;
case 3: propertyValue = "Two-chip color area sensor"; break;
case 4: propertyValue = "Three-chip color area sensor"; break;
case 5: propertyValue = "Color sequential area sensor"; break;
case 7: propertyValue = "Trilinear sensor"; break;
case 8: propertyValue = "Color sequential linear sensor"; break;
default: propertyValue = " reserved"; break;
}
}
break;
case 0x8822: // aperture
switch (ConvertToUInt16(property.Value))
{
case 0: propertyValue = "Not defined"; break;
case 1: propertyValue = "Manual"; break;
case 2: propertyValue = "Normal program"; break;
case 3: propertyValue = "Aperture priority"; break;
case 4: propertyValue = "Shutter priority"; break;
case 5: propertyValue = "Creative program (biased toward depth of field)"; break;
case 6: propertyValue = "Action program (biased toward fast shutter speed)"; break;
case 7: propertyValue = "Portrait mode (for closeup photos with the background out of focus)"; break;
case 8: propertyValue = "Landscape mode (for landscape photos with the background in focus)"; break;
default: propertyValue = "reserved"; break;
}
break;
case 0x9207: // metering mode
switch (ConvertToUInt16(property.Value))
{
case 0: propertyValue = "unknown"; break;
case 1: propertyValue = "Average"; break;
case 2: propertyValue = "CenterWeightedAverage"; break;
case 3: propertyValue = "Spot"; break;
case 4: propertyValue = "MultiSpot"; break;
case 5: propertyValue = "Pattern"; break;
case 6: propertyValue = "Partial"; break;
case 255: propertyValue = "Other"; break;
default: propertyValue = "reserved"; break;
}
break;
case 0x9208: // light source
{
switch (ConvertToUInt16(property.Value))
{
case 0: propertyValue = "unknown"; break;
case 1: propertyValue = "Daylight"; break;
case 2: propertyValue = "Fluorescent"; break;
//.........这里部分代码省略.........
示例5: Test_ToString
public void Test_ToString()
{
Rational rational = new Rational(0, 0);
Assert.AreEqual("Indeterminate", rational.ToString());
rational = new Rational(double.PositiveInfinity);
Assert.AreEqual("PositiveInfinity", rational.ToString());
rational = new Rational(double.NegativeInfinity);
Assert.AreEqual("PositiveInfinity", rational.ToString());
rational = new Rational(0, 1);
Assert.AreEqual("0", rational.ToString());
rational = new Rational(2, 1);
Assert.AreEqual("2", rational.ToString());
rational = new Rational(1, 2);
Assert.AreEqual("1/2", rational.ToString());
}
示例6: Main
/// Entry point to test some implemented functions
public static void Main(string[] args)
{
Rational a = new Rational(10, 21);
Rational b = new Rational(90, 18);
// Normalization
Console.WriteLine(a.ToString());
Console.WriteLine(b.Normalize().Fraction());
// Equals
Console.WriteLine(b.Normalize() == b);
Console.WriteLine(a.Normalize() == b);
// Sum
Console.WriteLine(a + b);
// Product
Console.WriteLine(a * b);
}