NaN, Zero, & Infinities
Upcoming SlideShare
Loading in...5
×
 

NaN, Zero, & Infinities

on

  • 452 views

My Method of the Month lightning talk for the Columbus Ruby Brigade's September 2011 meeting.

My Method of the Month lightning talk for the Columbus Ruby Brigade's September 2011 meeting.

Statistics

Views

Total Views
452
Slideshare-icon Views on SlideShare
450
Embed Views
2

Actions

Likes
0
Downloads
4
Comments
0

1 Embed 2

http://www.hanrss.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

NaN, Zero, & Infinities NaN, Zero, & Infinities Presentation Transcript

  • NaN, Zero, & Infinities Methods of the Month from Ruby’s Float Kevin Munc - @muncmanMonday, 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::NANMonday, 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 somethingMonday, September 19, 2011
  • zero? • Only true for 0.0 or -0.0 • 0.0.zero? => true • -0.0.zero? => true • 0.0001.zero? => falseMonday, 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 & ScarboroughMonday, 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 weirdMonday, 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 +infinityMonday, September 19, 2011
  • infinite? • (0.0).infinite? => nil (finite) • (0.0/0).infinite? => nil (NaN) • (1.0/0).infinite? => 1 • (-1.0/0).infinite? => -1Monday, September 19, 2011
  • infinite? • (1.0/0) => Infinity • (-1.0/0) => -Infinity • Float::INFINITYMonday, September 19, 2011
  • infinite? • Float::INFINITY + 100 => Infinity • Float::INFINITY - 100 => Infinity • Float::INFINITY * Float::INFINITY => Infinity • Float::INFINITY == Float::INFINITY => trueMonday, September 19, 2011
  • infinite? • Float::INFINITY == (1.0/0) => true • Float::INFINITY == (-1.0/0) => false • Float::INFINITY - Float::INFINITY => NaNMonday, 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