Skip to content

Commit 70613cd

Browse files
committed
[stdlib] Add exponentiation precedence group and operator
1 parent cd724d4 commit 70613cd

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

stdlib/public/core/Policy.swift

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ precedencegroup MultiplicationPrecedence {
368368
precedencegroup BitwiseShiftPrecedence {
369369
higherThan: MultiplicationPrecedence
370370
}
371-
371+
precedencegroup ExponentiationPrecedence {
372+
associativity: right
373+
higherThan: MultiplicationPrecedence
374+
}
372375

373376
//===----------------------------------------------------------------------===//
374377
// Standard operators
@@ -398,6 +401,7 @@ prefix operator ..<: Comparable
398401

399402
// "Exponentiative"
400403

404+
infix operator **: ExponentiationPrecedence
401405
infix operator <<: BitwiseShiftPrecedence, BinaryInteger
402406
infix operator &<<: BitwiseShiftPrecedence, FixedWidthInteger
403407
infix operator >>: BitwiseShiftPrecedence, BinaryInteger
@@ -463,6 +467,7 @@ infix operator ||: LogicalDisjunctionPrecedence, Bool
463467

464468
// Compound
465469

470+
infix operator **=: AssignmentPrecedence
466471
infix operator *=: AssignmentPrecedence, Numeric
467472
infix operator &*=: AssignmentPrecedence, FixedWidthInteger
468473
infix operator /=: AssignmentPrecedence, BinaryInteger
@@ -486,3 +491,48 @@ infix operator |=: AssignmentPrecedence, BinaryInteger
486491
// example of how this operator is used, and how its use can be hidden
487492
// from users.
488493
infix operator ~>
494+
495+
//===----------------------------------------------------------------------===//
496+
// Placeholder operator functions for diagnostic purposes
497+
//===----------------------------------------------------------------------===//
498+
499+
extension Float {
500+
@available(*, unavailable, message: "use 'Foundation.pow' instead")
501+
@_alwaysEmitIntoClient
502+
public static func ** (lhs: Self, rhs: Self) -> Self {
503+
fatalError("Not implemented")
504+
}
505+
@available(*, unavailable, message: "use 'Foundation.pow' instead")
506+
@_alwaysEmitIntoClient
507+
public static func **= (lhs: inout Self, rhs: Self) {
508+
fatalError("Not implemented")
509+
}
510+
}
511+
512+
extension Double {
513+
@available(*, unavailable, message: "use 'Foundation.pow' instead")
514+
@_alwaysEmitIntoClient
515+
public static func ** (lhs: Self, rhs: Self) -> Self {
516+
fatalError("Not implemented")
517+
}
518+
@available(*, unavailable, message: "use 'Foundation.pow' instead")
519+
@_alwaysEmitIntoClient
520+
public static func **= (lhs: inout Self, rhs: Self) {
521+
fatalError("Not implemented")
522+
}
523+
}
524+
525+
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
526+
extension Float80 {
527+
@available(*, unavailable, message: "use 'Foundation.pow' instead")
528+
@_alwaysEmitIntoClient
529+
public static func ** (lhs: Self, rhs: Self) -> Self {
530+
fatalError("Not implemented")
531+
}
532+
@available(*, unavailable, message: "use 'Foundation.pow' instead")
533+
@_alwaysEmitIntoClient
534+
public static func **= (lhs: inout Self, rhs: Self) {
535+
fatalError("Not implemented")
536+
}
537+
}
538+
#endif

0 commit comments

Comments
 (0)