Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SE-0246 Generic Math(s) Functions

SE-0246 Generic Math(s) Functions

Shigure Shimotori

April 10, 2019
Tweet

More Decks by Shigure Shimotori

Other Decks in Programming

Transcript

  1. SE-0246: GENERIC MATH(S) FUNCTIONS ࠓ೔࿩͢͜ͱ ▸ SE-0246ͷ಺༰ ▸ with modificationsͬͯͳʹ

    ▸ Ϟδϡʔϧ໊Ͳ͏͢Δ໰୊ ▸ logؔ਺ͷ໊લͲ͏͢Δ໰୊
  2. SE-0246: GENERIC MATH(S) FUNCTIONS SE-0246ͷϞνϕ ▸ C mathϥΠϒϥϦͷݺͼग़͕͠Πέͯͳ͍ ▸ Darwin͔GNU

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

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

    value: CGFloat = 0 sin(value) // SE-0246 // extension CGFloat: ElementaryFunction CGFloat.sin(0)
  5. 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 ※γάϞΠυؔ਺
  6. SE-0246: GENERIC MATH(S) FUNCTIONS ACCEPT͞ΕΔ·Ͱʹมߋ͞Εͨ͜ͱ ▸ Ұ෦ͷؔ਺͕ॳ౳ؔ਺͔Β࣮ؔ਺ߦ͖ʹ͞Εͨ ▸ atan2͸ඇ࣮਺ΛҾ਺ʹऔΒͳ͍ ▸

    erf, erfc, gamma, logGamma͸Ұ෦؀ڥͰ࢖͑ͳ͍͠ɺਖ਼֬ʹ͸
 ॳ౳ؔ਺͡Όͳ͍ ▸ ࣮ؔ਺ʹ௥Ճ: hypot ▸ ໊લۭؒͷมߋ ▸ ؔ਺Λ“Math”Լʹ·ͱΊΑ͏ͱࢥ͚ͬͯͨͲ΍Ίͨ
  7. 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
  8. 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 Modifications] 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.
  9. 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