Shop OBEX P1 Docs P2 Docs Learn Events
How does the prop handle a non integer number — Parallax Forums

How does the prop handle a non integer number

science_geekscience_geek Posts: 247
edited 2009-05-27 20:04 in Propeller 1
if i do the square root of a number and it turn out to not be an integer, what does the prop do, does it round up or down, or does it throw it out and outputs an error message

Comments

  • PhilldapillPhilldapill Posts: 1,283
    edited 2009-05-26 20:27
    It floors the number. That is IF you are using the regular, run-of-the-mill integar math. There is an object in the obex that allows you to do float math. I think it's somethink like "Math" or "Float. I'm sure someone who knows the name will guide you to it a little better.
  • science_geekscience_geek Posts: 247
    edited 2009-05-27 02:06
    what do you mean floors, i am outputting the number so i really cant use a noninteger value, i just need to know what happens to the result of an equation if its not an integer
  • RossHRossH Posts: 5,512
    edited 2009-05-27 02:36
    "floor" means to reduce the value to the largest integer lower than the number. e.g. floor(sqrt(10)) = 3

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • science_geekscience_geek Posts: 247
    edited 2009-05-27 02:58
    thank you so much, thats what i needed to happen
  • SRLMSRLM Posts: 5,045
    edited 2009-05-27 03:09
    floor = cut off the decimal portion ("truncate" it)
  • RossHRossH Posts: 5,512
    edited 2009-05-27 03:27
    @SLRM,

    That's true only for positive numbers, not for negatives - e.g. floor(-3.2) = -4, not -3

    But since we started out talking about square roots, I suppose science_geek is only dealing with positive numbers.

    Ross.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • ElectricAyeElectricAye Posts: 4,561
    edited 2009-05-27 05:33
    I am routinely getting burned by the different ways the Propeller and my add-ons handle different forms of numbers, such an integers and floating math functions (not to mention string values consisting of numbers), so I strongly suggest you look over the float math examples in the OBEX before you decide what you really need to do. It's easy to write code and think you've done the proper thing with your numbers.... until one day something glitches and only then you realize you didn't handle the math the right way.


    obex.parallax.com/objects/category/6/?page=1

    Do as I say, not as I do. smile.gif
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-05-27 19:24
    That's just a matter of the range that your testing did cover

    I always do extensive testings with extremly values to be sure that everything works right even with a value beeing a zero
    or very tiny or negative, or really huge.

    I do this REALLY ALWAYS even if I know in this method the values can NEVER get negative or bigger than 100
    I DO test it ALWAYS in general. Testing it this way keeps me away from thinking "oh here it doesn't matter"

    In earlier times I had enough cases where I thought "oh here it doesn't matter" and then bug came up later

    And by doing this I add code that catches bad values and make the code setting the value to a default-value or
    create debug-output that a value was out of expected range

    best regards

    Stefan
  • science_geekscience_geek Posts: 247
    edited 2009-05-27 20:04
    well, since this is for a cnc mill, i dont think that truncatting a value will do much since i cant use a value other than integers, granted there will be small steps in curves, but so small that you wont be able to notice it even when doing a very precise piece. and i wont be selling it to anyone except for my uncle if he wants one,·so it will always be a growing project,

    in the case of negative numbers and square roots, i kinda will get a negative number cause the code im using for circular interpolation is y= sqrt(r^2 - (x - h)), where y = y axis movement and·x =·x + 1 until x = 2r·since this equation only does half a circle i would have to also do a negative version counting x down and running the x axis in the opposit direction which would·need to be a negative number to give the second half of the cirlce, but i can just set the direction of y opposite to the first half of the circle

    if this doesnt make sense im sorry, it does in my mind
Sign In or Register to comment.