Grasshopper

algorithmic modeling for Rhino

Hi guys,

 

very beginner 's question, what's the meaning of maxvalue at here? what is the return?0.99?

 

Dim X As Double = Double.MaxValue

 

thanks!

 

Views: 364

Replies to This Discussion

Double.MaxValue, Single.MaxValue, Integer.MaxValue etc. etc. are all properties that return the highest possible valid number that can be represented by a specific numeric type. These will not be 'nice' numbers in base-10 because most of those types are based on base-2 logic.

If you want to know what number is represented by Double.MaxValue, you can always create one and display it or you can google it.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David, but what I feel strange here is in the sentance it defines x as one number but not a list of numbers, so how can you choose the "max" from just one number? 

 

I put the context here,

 

Function closestCircle(RefPt As point3d, Circles As list(Of Circle)) As circle    

  Dim minDist As Double = Double.MaxValue    

  Dim CirClosest As Circle

    For Each Sample As circle In Circles      

  Dim tmpDist As Double = sample.Center.DistanceTo(refPt) - sample.Radius      

  If tmpDist < minDist Then        

   minDist = tmpDist        

   CirClosest = Sample      

  End If    

 Next    

 closestCircle = CirClosest  

 End Function

 

Numbers that are stored digitally require a certain amount of bits to be stored in. There's a limited amount of bits in this universe so it not possible to represent certain numbers accurately. Pi is an example, it is transcendental and there simply aren't enough particles in this universe to encode all the unique decimals that make up Pi.

Matters are of course much worse in your average computer on Earth, different types of digital numbers are allotted fixed amounts of memory space. Bytes (0 to 255) are allowed 8 bits. Standard integers are allowed 32 bits. Standard double-precision floating point numbers are allowed 64 bits. There's only so many unique numbers you can make if all you have to work with are 64 on-off switches (2 to the power 64 to be precise). It stands to reason that one of these possible numbers is the lowest one and another the highest one.

Double.MaxValue returns the highest of all possible double-precision floating point numbers. There is no number higher than Double.MaxValue (unless you count Double.PositiveInfinity which isn't so much an actual number as a convention).

The most common reason for using Double.MaxValue in code is when you are looking for the lowest number in a list. What you do is iterate over the all the numbers in that list and remember the lowest one you found so far. By starting out with Double.MaxValue as 'the best answer so far' you guarantee that every other number will be either equal to or smaller than your starting value.

Put another way, Double.MaxValue isn't about getting the highest number in some collection of numbers, it's about getting the highest ever possible number.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you so much!!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service