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

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

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