Shop OBEX P1 Docs P2 Docs Learn Events
programming help — Parallax Forums

programming help

ArchiverArchiver Posts: 46,084
edited 2004-05-06 16:34 in General Discussion
Hi guys,
just wondering whether anyone can provide me with a simple example on
programming. I have

IF A > B THEN Left_Turn

but instead of A > B, i would like it to be maybe just 90% of B.
So the program i want is IF A > 90% of B THEN Left_Turn
just wondering how it is like in basicstamp language

thanks guys

Jeff

_________________________________________________________________
Watch LIVE baseball games on your computer with MLB.TV, included with MSN
Premium!
http://join.msn.com/?page=features/mlb&pgmarket=en-us/go/onm00200439ave/direct/01/

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-05-05 13:42
    Try

    IF A > (90*B)/100 THEN Left_Turn

    This presumes that 90*B<=65535! You have to do the multiplication first
    since it is integer math. For example, assume B=200.

    B*90 = 18000
    18000 / 100 = 180

    However, if you compute B * (90/100) then you get B*0 or 0!

    The Stamp evaluates left to right so the () are not strictly necessary, but
    I put them there to make the point that the order is very important.

    Regards,

    Al Williams
    AWC
    * NEW: Add floating point math and analog to your Stamp
    http://www.awce.com/pak12.htm




    Original Message
    From: Wu MengChe [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=QseQ5MbeF-mp6zUdpwYlPc55lwmMvGqRA71e9gBQzBepRCxGlNM9Wjz3wkMK3LW6ikN3QUOz9kv6uxTv]mengche@h...[/url
    Sent: Wednesday, May 05, 2004 12:29 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] programming help


    Hi guys,
    just wondering whether anyone can provide me with a simple example on
    programming. I have

    IF A > B THEN Left_Turn

    but instead of A > B, i would like it to be maybe just 90% of B. So the
    program i want is IF A > 90% of B THEN Left_Turn just wondering how it is
    like in basicstamp language

    thanks guys

    Jeff

    _________________________________________________________________
    Watch LIVE baseball games on your computer with MLB.TV, included with MSN
    Premium!
    http://join.msn.com/?page=features/mlb&pgmarket=en-us/go/onm00200439ave/dire
    ct/01/



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.

    Yahoo! Groups Links
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-05 18:20
    > just wondering whether anyone can provide me with a simple example on
    > programming. I have
    >
    > IF A > B THEN Left_Turn
    >
    > but instead of A > B, i would like it to be maybe just 90% of B.
    > So the program i want is IF A > 90% of B THEN Left_Turn
    > just wondering how it is like in basicstamp language

    if (A > (90 * B / 100)) THEN Left_Turn

    --
    Enjoy,
    George Warner,
    Schizophrenic Optimization Scientists
    Apple Developer Technical Support (DTS)
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-05 23:18
    --- In basicstamps@yahoogroups.com, George Warner <geowar@a...> wrote:
    > > just wondering whether anyone can provide me with a simple
    example on
    > > programming. I have
    > >
    > > IF A > B THEN Left_Turn
    > >
    > > but instead of A > B, i would like it to be maybe just 90% of B.
    > > So the program i want is IF A > 90% of B THEN Left_Turn
    > > just wondering how it is like in basicstamp language
    >
    > if (A > (90 * B / 100)) THEN Left_Turn

    Or, if you need to implement proper rounding:

    if (A > ((90 * B + 50)/ 100)) THEN Left_Turn
  • ArchiverArchiver Posts: 46,084
    edited 2004-05-06 16:34
    Also, check into the Stamp's */ operator:

    IF A > B */ 230 THEN Left_Turn

    That is saying 230/256 instead of 90/100. But the two fractions are
    very close. Another way is,

    IF A > B ** 58982 THEN Left_Turn

    which is saying 58982/65536, which is very close to 90/100.

    -- Tracy


    >--- In basicstamps@yahoogroups.com, George Warner <geowar@a...> wrote:
    >> > just wondering whether anyone can provide me with a simple
    >example on
    >> > programming. I have
    >> >
    >> > IF A > B THEN Left_Turn
    >> >
    >> > but instead of A > B, i would like it to be maybe just 90% of B.
    >> > So the program i want is IF A > 90% of B THEN Left_Turn
    >> > just wondering how it is like in basicstamp language
    >>
    >> if (A > (90 * B / 100)) THEN Left_Turn
    >
    >Or, if you need to implement proper rounding:
    >
    >if (A > ((90 * B + 50)/ 100)) THEN Left_Turn
Sign In or Register to comment.