Skip to Main Content
Ruby. Receptury
book

Ruby. Receptury

by Lucas Carlson, Leonard Richardson
November 2012
Intermediate to advanced content levelIntermediate to advanced
888 pages
54h 46m
Polish
Helion
Content preview from Ruby. Receptury

2.12. Liczby zespolone

Problem

Chcemy używać w języku Ruby liczb zespolonych i wykonywać na nich operacje arytmetyczne.

Rozwiązanie

Liczby zespolone reprezentowane są w języku Ruby przez klasę Complex. Klasa ta implementuje wszystkie operacje matematyczne i trygonometryczne, jakie zdefiniowane są dla liczb zespolonych.

require 'complex' Complex::I # => Complex(0, 1) a = Complex(1, 4) # => Complex(1, 4) a.real # => 1 #Część rzeczywista a.image # => 4 #Część urojona b = Complex(1.5, 4.25) # => Complex(1.5, 4.25) b + 1.5 # => Complex(3.0, 4.25) b + 1.5*Complex::I # => Complex(1.5, 5.75) a - b # => Complex(-0.5, -0.25) a * b # => Complex(-15.5, 10.25) b.conjugate # => Complex(1.5, -4.25) #Sprzężenie Math::sin(b) # => Complex(34.9720129257216, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ReasonML Quick Start Guide

ReasonML Quick Start Guide

Raphael Rafatpanah, Bruno Joseph D'mello
Microsoft Excel: Formeln & Funktionen - Das Maxibuch, 3., aktualisierte und erweiterte Auflage

Microsoft Excel: Formeln & Funktionen - Das Maxibuch, 3., aktualisierte und erweiterte Auflage

Egbert Jeschke, Eckehard Pfeifer, Helmut Reinke, Sara Unverhau, Bodo Fienitz
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao

Publisher Resources

ISBN: 9781457177453Errata Page