SlideShare a Scribd company logo
1 of 18
Download to read offline
NaN, Zero,
                              & Infinities
                         Methods of the Month from Ruby’s Float
                              Kevin Munc - @muncman




Monday, September 19, 2011
Numbers. Non-Numbers.
Monday, September 19, 2011
nan?
                   • True if the float is not a valid IEEE 754
                             floating point number.
                   • 0.0.nan? => false
                   • (0.0/0).nan? => true
                   • Float::NAN

Monday, September 19, 2011
nan?

                   • 0.0/0 => NaN
                   • This is in contrast to the
                             ZeroDivisionError that results when using
                             Fixnums to divide by zero.




Monday, September 19, 2011
Monday, September 19, 2011
Zero is worth something
Monday, September 19, 2011
zero?
                   • Only true for 0.0 or -0.0
                   • 0.0.zero? => true
                   • -0.0.zero? => true
                   • 0.0001.zero? => false

Monday, September 19, 2011
Tangent::Trivia
       “The centre of York station was used as
       the zero point for distance measurement
       for much of the rail network in the North
       East of England.”                 - http://www.flickr.com/photos/xerones/3887271255/




       The lines, from the top:
           1. Longlands Loop (Northallerton)
           2. Market Weighton & Beverley
           3. Micklefield Branch
           4. Raskelf Curve
           5. Sherburn Branch
           6. York & Harrogate
           7. York & Market Weighton
           8. York & Newcastle
           9. York & North Midland
           10. York & Scarborough




Monday, September 19, 2011
infinite? finite?
Monday, September 19, 2011
finite?
                   • True if the float is a valid IEEE floating point
                             number; true if not Infinity and not NaN.
                   • 1.0.finite? => true
                   • 0.0.finite? => true
                   • (0.0/0).finite? => false        (NaN)
                   • (1.0/0).finite? => false        (Infinity)


Monday, September 19, 2011
Infinity is a little weird
Monday, September 19, 2011
infinite?


           •      Returns nil if float is finite

           •      Returns nil if float is NaN

           •      Returns -1 if float is -infinity

           •      Returns +1 if float is +infinity




Monday, September 19, 2011
infinite?
                   • (0.0).infinite? => nil (finite)
                   • (0.0/0).infinite? => nil (NaN)
                   • (1.0/0).infinite? => 1
                   • (-1.0/0).infinite? => -1

Monday, September 19, 2011
infinite?

                   • (1.0/0) => Infinity
                   • (-1.0/0) => -Infinity
                   • Float::INFINITY


Monday, September 19, 2011
infinite?
                   • Float::INFINITY + 100 => Infinity
                   • Float::INFINITY - 100 => Infinity
                   • Float::INFINITY * Float::INFINITY => Infinity
                   • Float::INFINITY == Float::INFINITY => true

Monday, September 19, 2011
infinite?

                   • Float::INFINITY == (1.0/0) => true
                   • Float::INFINITY == (-1.0/0) => false
                   • Float::INFINITY - Float::INFINITY => NaN


Monday, September 19, 2011
Uses for Infinity?
                   • Range?
                    • everything = -Infinity..Infinity
                    • Versus Float::MAX ?
                   • To represent something completely
                             unbounded?
                   • Others?

Monday, September 19, 2011
questions.zero?
                  Photo Credits
        •      http://www.flickr.com/photos/shanedk/3959630757/


        •      http://www.flickr.com/photos/cogdog/3160739508/


        •      http://www.flickr.com/photos/shyald/3182510815/


        •      http://www.flickr.com/photos/affers/3183414031/


        •      http://www.flickr.com/photos/doug88888/4542924531/


        •      http://www.flickr.com/photos/libraryman/12835119/


        •      http://www.flickr.com/photos/xerones/3887271255/


        •      http://www.flickr.com/photos/jcolman/334602926/




Monday, September 19, 2011

More Related Content

More from Kevin Munc

Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)Kevin Munc
 
Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)Kevin Munc
 
cycle (MOTM 2010.07)
cycle (MOTM 2010.07)cycle (MOTM 2010.07)
cycle (MOTM 2010.07)Kevin Munc
 
empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)Kevin Munc
 
Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)Kevin Munc
 
Removing Methods (MOTM 2010.01)
Removing Methods (MOTM 2010.01)Removing Methods (MOTM 2010.01)
Removing Methods (MOTM 2010.01)Kevin Munc
 
The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)Kevin Munc
 
Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)Kevin Munc
 

More from Kevin Munc (8)

Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)
 
Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)
 
cycle (MOTM 2010.07)
cycle (MOTM 2010.07)cycle (MOTM 2010.07)
cycle (MOTM 2010.07)
 
empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)
 
Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)
 
Removing Methods (MOTM 2010.01)
Removing Methods (MOTM 2010.01)Removing Methods (MOTM 2010.01)
Removing Methods (MOTM 2010.01)
 
The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)
 
Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

NaN, Zero, & Infinities

  • 1. NaN, Zero, & Infinities Methods of the Month from Ruby’s Float Kevin Munc - @muncman Monday, September 19, 2011
  • 3. nan? • True if the float is not a valid IEEE 754 floating point number. • 0.0.nan? => false • (0.0/0).nan? => true • Float::NAN Monday, September 19, 2011
  • 4. nan? • 0.0/0 => NaN • This is in contrast to the ZeroDivisionError that results when using Fixnums to divide by zero. Monday, September 19, 2011
  • 6. Zero is worth something Monday, September 19, 2011
  • 7. zero? • Only true for 0.0 or -0.0 • 0.0.zero? => true • -0.0.zero? => true • 0.0001.zero? => false Monday, September 19, 2011
  • 8. Tangent::Trivia “The centre of York station was used as the zero point for distance measurement for much of the rail network in the North East of England.” - http://www.flickr.com/photos/xerones/3887271255/ The lines, from the top: 1. Longlands Loop (Northallerton) 2. Market Weighton & Beverley 3. Micklefield Branch 4. Raskelf Curve 5. Sherburn Branch 6. York & Harrogate 7. York & Market Weighton 8. York & Newcastle 9. York & North Midland 10. York & Scarborough Monday, September 19, 2011
  • 10. finite? • True if the float is a valid IEEE floating point number; true if not Infinity and not NaN. • 1.0.finite? => true • 0.0.finite? => true • (0.0/0).finite? => false (NaN) • (1.0/0).finite? => false (Infinity) Monday, September 19, 2011
  • 11. Infinity is a little weird Monday, September 19, 2011
  • 12. infinite? • Returns nil if float is finite • Returns nil if float is NaN • Returns -1 if float is -infinity • Returns +1 if float is +infinity Monday, September 19, 2011
  • 13. infinite? • (0.0).infinite? => nil (finite) • (0.0/0).infinite? => nil (NaN) • (1.0/0).infinite? => 1 • (-1.0/0).infinite? => -1 Monday, September 19, 2011
  • 14. infinite? • (1.0/0) => Infinity • (-1.0/0) => -Infinity • Float::INFINITY Monday, September 19, 2011
  • 15. infinite? • Float::INFINITY + 100 => Infinity • Float::INFINITY - 100 => Infinity • Float::INFINITY * Float::INFINITY => Infinity • Float::INFINITY == Float::INFINITY => true Monday, September 19, 2011
  • 16. infinite? • Float::INFINITY == (1.0/0) => true • Float::INFINITY == (-1.0/0) => false • Float::INFINITY - Float::INFINITY => NaN Monday, September 19, 2011
  • 17. Uses for Infinity? • Range? • everything = -Infinity..Infinity • Versus Float::MAX ? • To represent something completely unbounded? • Others? Monday, September 19, 2011
  • 18. questions.zero? Photo Credits • http://www.flickr.com/photos/shanedk/3959630757/ • http://www.flickr.com/photos/cogdog/3160739508/ • http://www.flickr.com/photos/shyald/3182510815/ • http://www.flickr.com/photos/affers/3183414031/ • http://www.flickr.com/photos/doug88888/4542924531/ • http://www.flickr.com/photos/libraryman/12835119/ • http://www.flickr.com/photos/xerones/3887271255/ • http://www.flickr.com/photos/jcolman/334602926/ Monday, September 19, 2011

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n