@@ -513,18 +513,111 @@ public func %=(lhs: inout CGFloat, rhs: CGFloat) {
513
513
// tgmath
514
514
//===----------------------------------------------------------------------===//
515
515
516
+ % from SwiftMathFunctions import *
517
+ extension CGFloat : Real {
518
+ % for func in ElementaryFunctions + RealFunctions:
519
+
520
+ @_alwaysEmitIntoClient
521
+ public static func ${ func . decl( " CGFloat" ) } {
522
+ return CGFloat( NativeType . ${ func . swiftName} ( ${ func . params( " " , " .native " ) } ) )
523
+ }
524
+ % end
525
+
526
+ @_alwaysEmitIntoClient
527
+ public static func pow( _ x: CGFloat , _ y: CGFloat ) -> CGFloat {
528
+ return CGFloat ( NativeType . pow ( x. native, y. native) )
529
+ }
530
+
531
+ @_alwaysEmitIntoClient
532
+ public static func pow( _ x: CGFloat , _ n: Int ) -> CGFloat {
533
+ return CGFloat ( NativeType . pow ( x. native, n) )
534
+ }
535
+
536
+ @_alwaysEmitIntoClient
537
+ public static func root( _ x: CGFloat , _ n: Int ) -> CGFloat {
538
+ return CGFloat ( NativeType . root ( x. native, n) )
539
+ }
540
+
541
+ @_alwaysEmitIntoClient
542
+ public static func atan2( y: CGFloat , x: CGFloat ) -> CGFloat {
543
+ return CGFloat ( NativeType . atan2 ( y: y. native, x: x. native) )
544
+ }
545
+
546
+ #if !os(Windows)
547
+ @_alwaysEmitIntoClient
548
+ public static func logGamma( _ x: CGFloat ) -> CGFloat {
549
+ return CGFloat ( NativeType . logGamma ( x. native) )
550
+ }
551
+ #endif
552
+ }
553
+
554
+ @available ( swift, deprecated: 5.1 , message: " Use `root(x, 3)`. " )
555
+ @_transparent
556
+ public func cbrt( _ x: CGFloat ) -> CGFloat {
557
+ return CGFloat . root ( x, 3 )
558
+ }
559
+
560
+ @available ( swift, deprecated: 5.1 , message: " Use CGFloat.minimum( ) or Swift.min( ) " )
561
+ @_transparent
562
+ public func fmin( _ x: CGFloat , _ y: CGFloat ) -> CGFloat {
563
+ return . minimum( x, y)
564
+ }
565
+
566
+ @available ( swift, deprecated: 5.1 , message: " Use CGFloat.maximum( ) or Swift.max( ) " )
567
+ @_transparent
568
+ public func fmax( _ x: CGFloat , _ y: CGFloat ) -> CGFloat {
569
+ return . maximum( x, y)
570
+ }
571
+
572
+ #if !os(Windows)
573
+ @available ( swift, deprecated: 5.1 , message: " Use (logGamma(x), signGamma(x)). " )
574
+ @_transparent
575
+ public func lgamma( _ x: CGFloat ) -> ( CGFloat , Int ) {
576
+ return ( CGFloat . logGamma ( x) , CGFloat . signGamma ( x) == . plus ? 1 : - 1 )
577
+ }
578
+ #endif
579
+
580
+ @available ( swift, deprecated: 5.1 , message: " Use `x.exponent` or `floor(log2(x))`. " )
581
+ @_transparent
582
+ public func logb( _ x: CGFloat ) -> CGFloat {
583
+ return CGFloat . log2 ( x) . rounded ( . down)
584
+ }
585
+
586
+ @available ( swift, deprecated: 5.1 , message: " Swift does not model dynamic rounding modes, use x.rounded(.toNearestOrEven). " )
587
+ @_transparent
588
+ public func nearbyint( _ x: CGFloat ) -> CGFloat {
589
+ return x. rounded ( . toNearestOrEven)
590
+ }
591
+
592
+ @available ( swift, deprecated: 5.1 , message: " Use the .nextUp or .nextDown property. " )
593
+ @_transparent
594
+ public func nextafter( _ x: CGFloat , _ y: CGFloat ) -> CGFloat {
595
+ return y > x ? x. nextUp : ( y < x ? x. nextDown : y)
596
+ }
597
+
598
+ @available ( swift, deprecated: 5.1 , message: " Swift does not model dynamic rounding modes, use x.rounded(.toNearestOrEven). " )
599
+ @_transparent
600
+ public func rint( _ x: CGFloat ) -> CGFloat {
601
+ return x. rounded ( . toNearestOrEven)
602
+ }
603
+
604
+ @available ( swift, deprecated: 5.1 , message: " Use `gamma(x)`. " )
605
+ @_transparent
606
+ public func tgamma( _ x: CGFloat ) -> CGFloat {
607
+ return CGFloat . gamma ( x)
608
+ }
609
+
516
610
% {
517
611
UnaryFunctions = [
518
612
'acos', 'asin', 'atan', 'cos', 'sin', 'tan',
519
613
'acosh', 'asinh', 'atanh', 'cosh', 'sinh', 'tanh',
520
614
'exp', 'exp2 ', 'expm1 ',
521
- 'log', 'log10 ', 'log1 p', 'log2 ', 'logb',
522
- 'cbrt', 'erf', 'erfc', 'tgamma',
523
- 'nearbyint', 'rint'
615
+ 'log', 'log10 ', 'log1 p', 'log2 ',
616
+ 'erf', 'erfc',
524
617
]
525
618
526
619
BinaryFunctions = [
527
- 'atan2 ', 'hypot', 'pow', 'copysign', 'nextafter' , ' fdim' , 'fmax' , 'fmin '
620
+ 'atan2 ', 'hypot', 'pow', 'copysign', 'fdim'
528
621
]
529
622
} %
530
623
@@ -571,18 +664,12 @@ public func ldexp(_ x: CGFloat, _ n: Int) -> CGFloat {
571
664
return CGFloat ( ldexp ( x. native, n) )
572
665
}
573
666
574
- @available ( swift, deprecated: 4.2 , message: " use the exponent property. " )
667
+ @available ( swift, deprecated: 4.2 , obsoleted : 5.1 , message: " use the exponent property. " )
575
668
@_transparent
576
669
public func ilogb( _ x: CGFloat ) -> Int {
577
670
return Int ( x. exponent)
578
671
}
579
672
580
- @_transparent
581
- public func lgamma( _ x: CGFloat ) -> ( CGFloat , Int ) {
582
- let ( value, sign) = lgamma ( x. native)
583
- return ( CGFloat ( value) , sign)
584
- }
585
-
586
673
@_transparent
587
674
public func remquo( _ x: CGFloat , _ y: CGFloat ) -> ( CGFloat , Int ) {
588
675
let ( rem, quo) = remquo ( x. native, y. native)
0 commit comments