PDA

View Full Version : تابع mod



GGRRSS_2
یک شنبه 11 آذر 1386, 22:17 عصر
همانگونه که مطلع میباشید تابع mod مانده یک تقسیم را میدهد در vb.net این تابع را نتوانستم پیدا کنم آیا حذف یا تابع دیگری معرفی شده است از همراهی شما متشکرم

mehdihamedali
یک شنبه 11 آذر 1386, 23:10 عصر
نه دوست عزیز کار میکنه
این هم من اصلی که این موضوع رو ثابت میکنه و خود ماکرو سافت داده


<DIV id=mainBody>

Divides two numbers and returns only the remainder.
number1 Mod number2

http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Parts

number1 Required. Any numeric expression.
number2 Required. Any numeric expression.

http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Supported Types

All numeric types, including the unsigned and floating-point types and Decimal.

http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Result

The result is the remainder left after number2 is divided into number1.
The / Operator (Visual Basic) (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/335e97f2-c434-439e-9064-76973a051101.htm) returns the full quotient, which retains the remainder.

http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Remarks

If number1 or number2 is a floating-point value, then division is carried out and the floating-point remainder is returned. The data type of the result is the smallest data type that can hold all possible values resulting from division with the data types of number1 and number2.
If number1 or number2 evaluates to Nothing (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/06176e2d-bbf7-4a37-afaa-a86ad21ee99f.htm), it is treated as zero.
http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Attempted Division by Zero


If number2 evaluates to zero, the behavior of the Mod operator depends on the data type of the operands. An integral division throws a http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Equivalent Formula</H1>In terms of traditional operators, a Mod b is equivalent to either of the following formulas:
a - (b * (a \ b))
a - (b * Int(a / b) + CSByte(Math.Sign(a) <> Math.Sign(b)))

http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Floating-point Imprecision

When you work with floating-point numbers, keep in mind that they do not always have a precise representation in memory. This could lead to unexpected results from certain operations, such as value comparison and the Mod operator. For more information, see Troubleshooting Data Types (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/90040d67-b630-4125-a6ae-37195b079042.htm).

http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Overloading

The Mod operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/8c513d38-246b-4fb7-8b75-29e1364e555b.htm).


http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>Example

The following example uses the Mod operator to divide two numbers and return only the remainder. If either number is a floating-point number, the result is a floating-point number representing the remainder.
Visual Basic http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/copycode.gif</IMG>Copy CodeDim testResult As DoubletestResult = 10 Mod 5testResult = 10 Mod 3testResult = 12 Mod 4.3testResult = 12.6 Mod 5testResult = 47.9 Mod 9.35
The expressions in the preceding example return values of 0, 1, 3.4, 2.6, and 1.15.
The following example demonstrates the potential imprecision of floating-point operands. In the first statement, the operands are Double, and 0.2 is an infinitely repeating binary fraction with a stored value of 0.20000000000000001. In the second statement, the literal type character D forces both operands to Decimal, and 0.2 has a precise representation.
Visual Basic http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/copycode.gif</IMG>Copy CodefirstResult = 2.0 Mod 0.2' Double operation returns 0.2, not 0.secondResult = 2D Mod 0.2D' Decimal operation returns 0.

http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/local/collapse_all.gif</IMG>See Also

Tasks

Troubleshooting Data Types (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/90040d67-b630-4125-a6ae-37195b079042.htm)
Reference

Arithmetic Operators (Visual Basic) (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/330178e0-a375-4742-b662-b3080c89fa54.htm)
Operator Precedence in Visual Basic (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/cbbdb282-f572-458e-a520-008a675f8063.htm)
Operators Listed by Functionality (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/d1fb027c-872b-4ccc-afc8-2380e3f65d4a.htm)
Concepts

Arithmetic Operators in Visual Basic (http://barnamenevis.org/forum/ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/325dac7a-ea4f-41d5-8b48-f6e904211569.htm)

amirsajjadi
دوشنبه 12 آذر 1386, 07:02 صبح
با سلام
شما توابع ریاضی رو میتونید توی کلاس Math پیدا کنید

__H2__
دوشنبه 12 آذر 1386, 13:43 عصر
سلام
مشکل شما آنجا است که Mod تابع نیست! Mod یک اپراتور است، یک کلمه کلیدی...
مثل And یا Or یا + یا - ,....

و این اپراتور همچنان وجود دارد ووجود خواهد داشت


Dim i AS Integer = 25 Mod 2