Skip to content

Commit 94f252a

Browse files
committed
[stdlib] Add exponentiation precedence and operator
1 parent 58a5010 commit 94f252a

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,30 @@ extension ${Self} {
12431243
}
12441244
}
12451245

1246+
//===----------------------------------------------------------------------===//
1247+
// Placeholder Operators
1248+
//===----------------------------------------------------------------------===//
1249+
1250+
// TODO: Remove these operators once protocol-based math functions are
1251+
// incorporated from Swift Numerics into the standard library.
1252+
1253+
${Availability(bits)}
1254+
extension ${Self} {
1255+
@_alwaysEmitIntoClient
1256+
@available(*, unavailable,
1257+
message: "Import C standard library or Foundation to use 'pow' instead")
1258+
public static func ** (_ lhs: Self, _ rhs: Self) -> Self {
1259+
fatalError()
1260+
}
1261+
1262+
@_alwaysEmitIntoClient
1263+
@available(*, unavailable,
1264+
message: "Import C standard library or Foundation to use 'pow' instead")
1265+
public static func **= (_ lhs: inout Self, _ rhs: Self) {
1266+
fatalError()
1267+
}
1268+
}
1269+
12461270
//===----------------------------------------------------------------------===//
12471271
// Strideable Conformance
12481272
//===----------------------------------------------------------------------===//
@@ -1346,10 +1370,6 @@ internal struct _${Self}AnyHashableBox: _AnyHashableBox {
13461370
${Availability(bits)}
13471371
extension ${Self} : ConcurrentValue { }
13481372

1349-
//===----------------------------------------------------------------------===//
1350-
// Deprecated operators
1351-
//===----------------------------------------------------------------------===//
1352-
13531373
% if bits in [16,80]:
13541374
#else
13551375

@@ -1374,6 +1394,10 @@ public struct ${Self} {
13741394
% end
13751395
% end # for bits in all_floating_point_types
13761396

1397+
//===----------------------------------------------------------------------===//
1398+
// Deprecated Operators
1399+
//===----------------------------------------------------------------------===//
1400+
13771401
@_transparent
13781402
@available(*, unavailable,
13791403
message: "For floating point numbers use truncatingRemainder instead")

stdlib/public/core/Policy.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -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
@@ -397,6 +400,7 @@ prefix operator ..<: Comparable
397400
// Standard infix operators.
398401

399402
// "Exponentiative"
403+
infix operator **: ExponentiationPrecedence
400404

401405
infix operator <<: BitwiseShiftPrecedence, BinaryInteger
402406
infix operator &<<: BitwiseShiftPrecedence, FixedWidthInteger
@@ -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

0 commit comments

Comments
 (0)