CKTIS / C#
System.Math: odniesienie praktyczne
System.Math: odniesienie praktyczne: Math udostępnia statyczne funkcje liczbowe dla typów wbudowanych.
Wersja: .NET API; verified on .NET 10.0.14
Składnia
System.Math /* select a documented member or constructor */Math udostępnia statyczne funkcje liczbowe dla typów wbudowanych.
Stosuj do clamp, potęg, pierwiastków i zaokrągleń z jawnym wyborem przeciążenia.
Float/double mogą dać NaN lub nieskończoność i mają błędy reprezentacji; pieniądze zwykle wymagają decimal.
Math.Clamp wymaga min <= max; Abs najmniejszej wartości signed może zgłosić OverflowException.
Kompletny program rzeczywiście używa System.Math; oczekiwany stdout to dokładnie 10.
Przykłady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
Console.WriteLine(Math.Clamp(12, 0, 10));
Wynik
10
Kompletny program rzeczywiście używa `System.Math`; oczekiwany stdout to dokładnie `10`.