Shigure Shimotori
April 10, 2019
2.4k

# SE-0246 Generic Math(s) Functions

April 10, 2019

## Transcript

5. ### SE-0246: GENERIC MATH(S) FUNCTIONS ࠓ೔࿩͢͜ͱ ▸ SE-0246ͷ಺༰ ▸ with modiﬁcationsͬͯͳʹ

▸ Ϟδϡʔϧ໊Ͳ͏͢Δ໰୊ ▸ logؔ਺ͷ໊લͲ͏͢Δ໰୊

7. ### SE-0246: GENERIC MATH(S) FUNCTIONS SE-0246ͷϞνϕ ▸ C mathϥΠϒϥϦͷݺͼग़͕͠Πέͯͳ͍ ▸ Darwin͔GNU

C͔Ͱimportʹ෼ذ͕ൃੜ͢Δ ▸ protocol (Binary)FloatingPoint͕Πέͯͳ͍ ▸ CGFloat, Double, Float, Float80 \in BinaryFloatingPoint ▸ ͜ͷprotocolΛ࢖ͬͯ਺஋ܭࢉΛߟ͑Δͷ͸ෆศ
8. ### SE-0246: GENERIC MATH(S) FUNCTIONS SE-0246ͰఏҊ͞Εͨ͜ͱ ▸ protocol ElementaryFunctionsͱprotocol RealΛ࡞Δ ▸

ॳ౳ؔ਺ηοτ \subset ࣮ؔ਺ηοτ ▸ staticؔ਺ͷ͔ͨͪͰܭࢉͰ͖ΔΑ͏ʹ͢Δprotocol ▸ ͜ΕͰࠓޙ΋ͬͱ֦ு͍͚ͯ͠Δͧʂ ▸ ෳૉ਺ͱ͔SIMDͱ͔ ▸ IEEE 754ͷ࣮૷͓͢͢Ίؔ਺Λίϯϓ͢Δͱ͔
9. ### SE-0246: GENERIC MATH(S) FUNCTIONS ৽چൺֱ - SINؔ਺Λ࢖͏ // 今のSwift let

value: CGFloat = 0 sin(value) // SE-0246 // extension CGFloat: ElementaryFunction CGFloat.sin(0)
10. ### SE-0246: GENERIC MATH(S) FUNCTIONS ৽چൺֱ - SIGMOIDؔ਺Λఆٛ͢Δ // エラー。全浮動小数点数型を一括で扱えない func

sigmoid<T: FloatingPoint>(_ x: T) -> T { return 1/(1 + exp(-x)) } // SE-0246ならElementaryFunctionsと一言書けばよくなる func sigmoid<T: ElementaryFunctions>(_ x: T) -> T { return 1/(1 + T.exp(-x)) } σ(x) = 1 1 + e−x ※γάϞΠυؔ਺

13. ### SE-0246: GENERIC MATH(S) FUNCTIONS ACCEPT͞ΕΔ·Ͱʹมߋ͞Εͨ͜ͱ ▸ Ұ෦ͷؔ਺͕ॳ౳ؔ਺͔Β࣮ؔ਺ߦ͖ʹ͞Εͨ ▸ atan2͸ඇ࣮਺ΛҾ਺ʹऔΒͳ͍ ▸

erf, erfc, gamma, logGamma͸Ұ෦؀ڥͰ࢖͑ͳ͍͠ɺਖ਼֬ʹ͸  ॳ౳ؔ਺͡Όͳ͍ ▸ ࣮ؔ਺ʹ௥Ճ: hypot ▸ ໊લۭؒͷมߋ ▸ ؔ਺Λ“Math”Լʹ·ͱΊΑ͏ͱࢥ͚ͬͯͨͲ΍Ίͨ

15. ### SE-0246: GENERIC MATH(S) FUNCTIONS ϞδϡʔϧͲ͏͢Δ໰୊ ▸ MathϞδϡʔϧͰimport໰୊Λղܾ͢Δͭ΋Γ…ͩͬͨ ▸ αʔυύʔςΟϥΠϒϥϦͰ͢ͰʹMathͷ໊Λ࢖͍ͬͯΔ ▸

SwiftϞδϡʔϧʹ͢ͰʹmathͬΆ͍ؔ਺͕͋Δ ↓ ͱΓ͋͑ͣࠓճ͸Swiftʹ௚઀ಥͬࠐΉ͚ͩʹ͠Α͏ͥʂ

17. ### SE-0246: GENERIC MATH(S) FUNCTIONS ֤ݴޠͷର਺ؔ਺ͷ໊લ ࣗવର਺ ৗ༻ର਺ ΧελϜ Swift log

log10 N/A <cmath> log log10 N/A java.lang.Math log log10 N/A kotlin.math ln log10 log
18. ### SE-0246: GENERIC MATH(S) FUNCTIONS ͰɺͲ͏ͯ͠SWIFT͸LNͰ͸ͳ͘LOGʹͨ͠ͷ ▸ C++͕ͦ͏͔ͩΒ ▸ lnͩͱ໊લ͕୹͗͢Δ͔Β ▸

inͱฆΒΘ͍͔͠Β { x in ln(x) } { x in log(x) }

20. ### SE-0246: GENERIC MATH(S) FUNCTIONS SE-0246͸͜Μͳײ͡ʂ ▸ ͍Ζ͍Ζͳܭࢉ͕Ͱ͖ΔΑ͏ʹͳΔΑ ▸ ࠓޙ͞ΒʹͰ͖Δ͜ͱ͕૿͑ͦ͏ͩΑ ▸

࣮ͬͦ͘͞૷͚ͨ͠Ͳޓ׵ੑςετʁͰࣦഊ͔ͨ͠Βෆे෼
21. ### SE-0246: GENERIC MATH(S) FUNCTIONS ࢀߟจݙͱ͔ͦ͏͍͏ͷ ▸ swift-evolution/0246-mathable.md at master ·

apple/swift-evolution ▸ Math functions for Swift by stephentyrone · Pull Request #23140 · apple/swift ▸ Revert SE-0246 by stephentyrone · Pull Request #23800 · apple/swift ▸ SE-0246: Generic Math(s) Functions - Proposal Reviews - Swift Forums ▸ [Accepted with Modiﬁcations] SE-0246: Generic Math Functions - Announcements - Swift Forums ▸ Generic “math functions” - Pitches - Swift Forums ▸ apple/swift-source-compat-suite: The infrastructure and project index comprising the Swift source compatibility suite.
22. ### SE-0246: GENERIC MATH(S) FUNCTIONS ࢀߟจݙͱ͔ͦ͏͍͏ͷ ▸ 754-2008 - IEEE Standard

for Floating-Point Arithmetic - IEEE Standard ▸ <cmath> (math.h) - C++ Reference ▸ Math (Java SE 12 & JDK 12 ) ▸ kotlin.math - Kotlin Programming Language