SE-0246 Generic Math(s) Functions

SE-0246 Generic Math(s) Functions

Bf65cc9bdf26321a7579ddca7930cd10?s=128

Shigure Shimotori

April 10, 2019
Tweet

Transcript

  1. SE-0246:
 GENERIC MATH(S) FUNCTIONS OTEMACHI.SWIFT #3

  2. SE-0246: GENERIC MATH(S) FUNCTIONS ࣗݾ঺հ ▸ S_Shimotori ▸ ඍੵ΋ઢܗ΋Ͱ͖ͳ͔ͬͨΑ…

  3. SE-0246:
 GENERIC MATH(S) FUNCTIONS

  4. None
  5. ਺ֶͬΆ͍ܭࢉ͕ ͍Ζ͍ΖͰ͖Δ༧ײʂʂʂʂ

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

    ▸ Ϟδϡʔϧ໊Ͳ͏͢Δ໰୊ ▸ logؔ਺ͷ໊લͲ͏͢Δ໰୊
  7. SE-0246ͷ಺༰

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

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

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

    value: CGFloat = 0 sin(value) // SE-0246 // extension CGFloat: ElementaryFunction CGFloat.sin(0)
  11. 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 ※γάϞΠυؔ਺
  12. None
  13. None
  14. WITH MODIFICATION
 ͬͯͳʹ

  15. SE-0246: GENERIC MATH(S) FUNCTIONS ACCEPTED **WITH MODIFICATIONS** ▸ Կ͔ٞ࿦Λͨ͠ܗ੻͕͋Δʂ

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

    erf, erfc, gamma, logGamma͸Ұ෦؀ڥͰ࢖͑ͳ͍͠ɺਖ਼֬ʹ͸
 ॳ౳ؔ਺͡Όͳ͍ ▸ ࣮ؔ਺ʹ௥Ճ: hypot ▸ ໊લۭؒͷมߋ ▸ ؔ਺Λ“Math”Լʹ·ͱΊΑ͏ͱࢥ͚ͬͯͨͲ΍Ίͨ
  17. Ϟδϡʔϧ Ͳ͏͢Δ໰୊

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

    SwiftϞδϡʔϧʹ͢ͰʹmathͬΆ͍ؔ਺͕͋Δ ↓ ͱΓ͋͑ͣࠓճ͸Swiftʹ௚઀ಥͬࠐΉ͚ͩʹ͠Α͏ͥʂ
  19. LOGؔ਺ͷ໊લ
 Ͳ͏͢Δ໰୊

  20. 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
  21. SE-0246: GENERIC MATH(S) FUNCTIONS ͰɺͲ͏ͯ͠SWIFT͸LNͰ͸ͳ͘LOGʹͨ͠ͷ ▸ C++͕ͦ͏͔ͩΒ ▸ lnͩͱ໊લ͕୹͗͢Δ͔Β ▸

    inͱฆΒΘ͍͔͠Β { x in ln(x) } { x in log(x) }
  22. ·ͱΊ

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

    ࣮ͬͦ͘͞૷͚ͨ͠Ͳޓ׵ੑςετʁͰࣦഊ͔ͨ͠Βෆे෼
  24. 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.
  25. 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