Files
swift-mirror/stdlib/objc/Darwin/tgmath.swift.gyb
Jordan Rose cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00

309 lines
8.3 KiB
Swift

%# -*- mode: swift -*-
%# Ignore the following admonition; it applies to the resulting .swift file only
//// Automatically Generated From tgmath.swift.gyb. Do Not Edit Directly
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
%{
# Don't need 64-bit (Double/CDouble) overlays. The ordinary C imports work fine.
# FIXME: need 80-bit (Float80/long double) versions when long double is imported
overlayFloatBits = [32] # 80
allFloatBits = [32, 64] # 80
def floatName(bits):
if bits == 32:
return 'Float'
if bits == 64:
return 'Double'
if bits == 80:
return 'Float80'
def cFloatName(bits):
if bits == 32:
return 'CFloat'
if bits == 64:
return 'CDouble'
if bits == 80:
return 'CLongDouble'
def cFuncSuffix(bits):
if bits == 32:
return 'f'
if bits == 64:
return ''
if bits == 80:
return 'l'
# Each of the following lists is ordered to match math.h
# (T) -> T
# These functions do not have a corresponding LLVM intrinsic
UnaryFunctions = ['acos', 'asin', 'atan', 'tan',
'acosh', 'asinh', 'atanh', 'cosh', 'sinh', 'tanh',
'expm1',
'log1p', 'logb',
'cbrt', 'erf', 'erfc', 'tgamma',
]
# These functions have a corresponding LLVM intrinsic
# We call this intrinsic via the Builtin method so keep this list in
# sync with core/BuiltinMath.swift.gyb
UnaryIntrinsicFunctions = ['cos', 'sin',
'exp', 'exp2',
'log', 'log10', 'log2',
'fabs', 'sqrt',
'ceil', 'floor', 'nearbyint', 'rint', 'round', 'trunc',
]
# (T, T) -> T
BinaryFunctions = ['atan2', 'hypot', 'pow',
# FIXME: rdar://17275152 call to fmodf causes deserialization crash
# 'fmod',
'remainder', 'copysign', 'nextafter', 'fdim', 'fmax', 'fmin']
# These functions have special implementations.
OtherFunctions = ['fpclassify',
'isnormal', 'isfinite', 'isinf', 'isnan', 'signbit',
'modf', 'ldexp', 'frexp', 'ilogb', 'scalbn', 'lgamma',
'remquo', 'nan', 'fma',
'jn', 'yn']
# These functions are imported correctly as-is.
OkayFunctions = ['j0', 'j1', 'y0', 'y1']
# These functions are not supported for various reasons.
UnhandledFunctions = ['math_errhandling', 'scalbln',
'lrint', 'lround', 'llrint', 'llround', 'nexttoward',
'isgreater', 'isgreaterequal', 'isless', 'islessequal',
'islessgreater', 'isunordered', '__exp10',
'__sincos', '__cospi', '__sinpi', '__tanpi', '__sincospi']
def AllFloatTypes():
for bits in allFloatBits:
yield floatName(bits), cFloatName(bits), cFuncSuffix(bits)
def OverlayFloatTypes():
for bits in overlayFloatBits:
yield floatName(bits), cFloatName(bits), cFuncSuffix(bits)
def TypedUnaryFunctions():
for ufunc in UnaryFunctions:
for bits in overlayFloatBits:
yield floatName(bits), cFloatName(bits), cFuncSuffix(bits), ufunc
def TypedUnaryIntrinsicFunctions():
for ufunc in UnaryIntrinsicFunctions:
for bits in allFloatBits:
yield floatName(bits), ufunc
def TypedBinaryFunctions():
for bfunc in BinaryFunctions:
for bits in overlayFloatBits:
yield floatName(bits), cFloatName(bits), cFuncSuffix(bits), bfunc
}%
// Unary functions
// Note these do not have a corresponding LLVM intrinsic
% for T, CT, f, ufunc in TypedUnaryFunctions():
@transparent @public
func ${ufunc}(x: ${T}) -> ${T} {
return ${T}(${ufunc}${f}(${CT}(x)))
}
% end
// Unary intrinsic functions
// Note these have a corresponding LLVM intrinsic
% for T, ufunc in TypedUnaryIntrinsicFunctions():
@transparent @public
func ${ufunc}(x: ${T}) -> ${T} {
return _${ufunc}(x)
}
% end
// Binary functions
% for T, CT, f, bfunc in TypedBinaryFunctions():
@transparent @public
func ${bfunc}(lhs: ${T}, rhs: ${T}) -> ${T} {
return ${T}(${bfunc}${f}(${CT}(lhs), ${CT}(rhs)))
}
% end
// Other functions
% # These are AllFloatTypes not OverlayFloatTypes because of the Int return.
% for T, CT, f in AllFloatTypes():
% if f == '':
% f = 'd'
@transparent @public
func fpclassify(x: ${T}) -> Int {
return Int(__fpclassify${f}(${CT}(x)))
}
% end
% # These are AllFloatTypes not OverlayFloatTypes because we need to cover
% # them all because C's declarations are compiler builtins.
% for T, CT, f in AllFloatTypes():
@transparent @public
func isnormal(value: ${T}) -> Bool {
return value.isNormal
}
@transparent @public
func isfinite(value: ${T}) -> Bool {
return value.isFinite
}
@transparent @public
func isinf(value: ${T}) -> Bool {
return value.isInfinite
}
@transparent @public
func isnan(value: ${T}) -> Bool {
return value.isNaN
}
@transparent @public
func signbit(value: ${T}) -> Int {
return value.isSignMinus ? 1 : 0
}
% end
% # These are AllFloatTypes not OverlayFloatTypes because of the tuple return.
% for T, CT, f in AllFloatTypes():
@transparent @public
func modf(value: ${T}) -> (${T}, ${T}) {
var ipart = ${CT}(0)
let fpart = modf${f}(${CT}(value), &ipart)
return (${T}(ipart), ${T}(fpart))
}
% end
% # This is AllFloatTypes not OverlayFloatTypes because of the Int parameter.
% for T, CT, f in AllFloatTypes():
@transparent @public
func ldexp(x: ${T}, n: Int) -> ${T} {
return ${T}(ldexp${f}(${CT}(x), CInt(n)))
}
% end
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
% for T, CT, f in AllFloatTypes():
@transparent @public
func frexp(value: ${T}) -> (${T}, Int) {
var exp = CInt(0)
let frac = frexp${f}(${CT}(value), &exp)
return (${T}(frac), Int(exp))
}
% end
% # This would be AllFloatTypes not OverlayFloatTypes because of the Int return.
% # ... except we need an asmname to avoid an overload ambiguity.
% for T, CT, f in OverlayFloatTypes():
@transparent @public
func ilogb(x: ${T}) -> Int {
return Int(ilogb${f}(${CT}(x)))
}
% end
@asmname("ilogb")
func _swift_Darwin_ilogb(value: CDouble) -> CInt
@transparent @public
func ilogb(x: Double) -> Int {
return Int(_swift_Darwin_ilogb(CDouble(x)))
}
% # This is AllFloatTypes not OverlayFloatTypes because of the Int parameter.
% for T, CT, f in AllFloatTypes():
@transparent @public
func scalbn(x: ${T}, n: Int) -> ${T} {
return ${T}(scalbn${f}(${CT}(x), CInt(n)))
}
% end
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
% for T, CT, f in AllFloatTypes():
% # The real lgamma_r is not imported because it hides behind macro _REENTRANT.
@asmname("lgamma${f}_r")
func _swift_Darwin_lgamma${f}_r(${CT}, UnsafePointer<CInt>) -> ${CT}
@transparent @public
func lgamma(x: ${T}) -> (${T}, Int) {
var sign = CInt(0)
let value = withUnsafePointer(&sign) {
(signp: UnsafePointer<CInt>) -> ${CT} in
return _swift_Darwin_lgamma${f}_r(${CT}(x), signp)
}
return (${T}(value), Int(sign))
}
% end
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
% for T, CT, f in AllFloatTypes():
@transparent @public
func remquo(x: ${T}, y: ${T}) -> (${T}, Int) {
var quo = CInt(0)
let rem = remquo${f}(${CT}(x), ${CT}(y), &quo)
return (${T}(rem), Int(quo))
}
% end
% # This is AllFloatTypes not OverlayFloatTypes because of the String parameter.
% for T, CT, f in AllFloatTypes():
@transparent @public
func nan(tag: String) -> ${T} {
return tag.withCString { (cstr: CString)->${T} in
return ${T}(nan${f}(cstr))
}
}
% end
% for T, CT, f in OverlayFloatTypes():
@transparent @public
func fma(x: ${T}, y: ${T}, z: ${T}) -> ${T} {
return ${T}(fma${f}(${CT}(x), ${CT}(y), ${CT}(z)))
}
% end
% # These C functions only support double. The overlay fixes the Int parameter.
@transparent @public
func jn(n: Int, x: Double) -> Double {
return jn(CInt(n), x)
}
@transparent @public
func yn(n: Int, x: Double) -> Double {
return yn(CInt(n), x)
}
% end