Weitere ähnliche Inhalte
Ähnlich wie 2015 02-18 xxx-literalconvertible (20)
Mehr von Taketo Sano (18)
Kürzlich hochgeladen (20)
2015 02-18 xxx-literalconvertible
- 5. import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible {
let x: Double
let y: Double
init(_ x: Double, _ y: Double) {
self.x = x
self.y = y
}
init(_ x: Double) {
self.x = x
self.y = 0
}
init(integerLiteral x: IntegerLiteralType) {
self.x = Double(x)
self.y = 0
}
init(floatLiteral x: FloatLiteralType) {
self.x = x
self.y = 0
}
init(r: Double, θ: Double) {
self.x = r * cos(θ)
self.y = r * sin(θ)
}
}
func == (z: Complex, w: Complex) -> Bool {
return z.x == w.x && z.y == w.y
}
func Re(a: Complex) -> Double {
return a.x
}
func Im(a: Complex) -> Double {
- 6. import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible {
let x: Double
let y: Double
init(_ x: Double, _ y: Double) {
self.x = x
self.y = y
}
init(_ x: Double) {
self.x = x
self.y = 0
}
init(integerLiteral x: IntegerLiteralType) {
self.x = Double(x)
self.y = 0
}
init(floatLiteral x: FloatLiteralType) {
self.x = x
self.y = 0
}
init(r: Double, θ: Double) {
self.x = r * cos(θ)
self.y = r * sin(θ)
}
}
func == (z: Complex, w: Complex) -> Bool {
return z.x == w.x && z.y == w.y
}
func Re(a: Complex) -> Double {
return a.x
}
func Im(a: Complex) -> Double {
- 7. import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible {
let x: Double
let y: Double
init(_ x: Double, _ y: Double) {
self.x = x
self.y = y
}
init(_ x: Double) {
self.x = x
self.y = 0
}
init(integerLiteral x: IntegerLiteralType) {
self.x = Double(x)
self.y = 0
}
init(floatLiteral x: FloatLiteralType) {
self.x = x
self.y = 0
}
init(r: Double, θ: Double) {
self.x = r * cos(θ)
self.y = r * sin(θ)
}
}
func == (z: Complex, w: Complex) -> Bool {
return z.x == w.x && z.y == w.y
}
func Re(a: Complex) -> Double {
return a.x
}
func Im(a: Complex) -> Double {
- 9. let z = 2 + 3 * iz
{
Complex(0, 1) 定数として定義してある
こういう風に書ける
- 10. let z = 2 + 3 * i
こういう風に書ける
{
Complex(3, 0) * Complex(0, 1)
z
{
Complex(0, 1)
- 11. let z = 2 + 3 * i
こういう風に書ける
{
Complex(3, 0) * Complex(0, 1)
{
z
{
Complex(0, 1)
Complex(2, 0) + Complex(3, 0) * Complex(0, 1)
- 12. let z = 2 + 3 * i
こういう風に書ける
{
Complex(3, 0) * Complex(0, 1)
{
Complex(2, 0) + Complex(3, 0) * Complex(0, 1)
z
let z: Complex = Complex(2, 0) + Complex(3, 0) * Complex(0, 1)
{
{
Complex(0, 1)
- 14. i * i == -1
{
Complex(0, 1) * Complex(0, 1)
- 15. i * i == -1
{
Complex(0, 1) * Complex(0, 1)
{
Complex(0, 1) * Complex(0, 1) == Complex(1, 0)
- 17. let r = 2.0
let θ = M_PI / 4
let z = r * (cos(θ) + i * cos(θ))
- 18. let r = 2.0
let θ = M_PI / 4
let z = r * (cos(θ) + i * cos(θ))
!?
- 19. let i = Complex(0, 1)
let a = -1
i * i == a
- 20. let i = Complex(0, 1)
let a = -1
i * i == a
…???
- 21. import Foundation
struct Complex: Equatable, IntegerLiteralConvertible, FloatLiteralConvertible {
let x: Double
let y: Double
init(_ x: Double, _ y: Double) {
self.x = x
self.y = y
}
init(_ x: Double) {
self.x = x
self.y = 0
}
init(integerLiteral x: IntegerLiteralType) {
self.x = Double(x)
self.y = 0
}
init(floatLiteral x: FloatLiteralType) {
self.x = x
self.y = 0
}
init(r: Double, θ: Double) {
self.x = r * cos(θ)
self.y = r * sin(θ)
}
}
func == (z: Complex, w: Complex) -> Bool {
return z.x == w.x && z.y == w.y
}
func Re(a: Complex) -> Double {
return a.x
}
func Im(a: Complex) -> Double {
- 29. let url: NSURL = “http://yahoo.co.jp”
let image: UIImage = “image.png"
let color: UIColor = 0x722F37
- 30. let url: NSURL = “http://yahoo.co.jp”
let image: UIImage = “image.png"
let color: UIColor = 0x722F37
↑ Swift 1.0 でできてたのが、1.1 でできなくなった…