التابع Complex‎ الخاص بالصنف Kernel في روبي

من موسوعة حسوب
< Ruby‏ | Kernel
مراجعة 23:36، 20 أكتوبر 2018 بواسطة محمد-بغات (نقاش | مساهمات) (أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع <code>Complex‎</code> الخاص بالصنف <code>Kernel</code> في روبي}}</noinclude> تصنيف: Ruby تصن...')
(فرق) → مراجعة أقدم | المراجعة الحالية (فرق) | مراجعة أحدث ← (فرق)
اذهب إلى التنقل اذهب إلى البحث

يعيد التابع ناتج التعبير x + i * y؛ حيث i هو الوحدة التخيلية العقدية.

صياغة شكل السلسلة النصية:

string form = extra spaces , complex , extra spaces ;
complex = real part | [ sign ] , imaginary part
        | real part , sign , imaginary part
        | rational , "@" , rational ;
real part = rational ;
imaginary part = imaginary unit | unsigned rational , imaginary unit ;
rational = [ sign ] , unsigned rational ;
unsigned rational = numerator | numerator , "/" , denominator ;
numerator = integer part | fractional part | integer part , fractional part ;
denominator = digits ;
integer part = digits ;
fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
imaginary unit = "i" | "I" | "j" | "J" ;
sign = "-" | "+" ;
digits = digit , { digit | "_" , digit };
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
extra spaces = ? \s* ? ;

انظر String#to_c.

البنية العامة

Complex(x[, y])    numeric

المعاملات

x‎

y‎

القيمة المُعادة

أمثلة

مثال على استخدام التابع Complex‎:

Complex(1, 2)    #=> (1+2i)
Complex('1+2i')  #=> (1+2i)
Complex(nil)     #=> TypeError
Complex(1, nil)  #=> TypeError

انظر أيضا

مصادر