Shop OBEX P1 Docs P2 Docs Learn Events
SGN() — Parallax Forums

SGN()

SailerManSailerMan Posts: 337
edited 2007-12-27 21:56 in General Discussion
What is the best way to simulate the command SGN(Value) from other BASIC dialects. It equals 1 if Value is Positive, -1 if Value is Negative and 0 if Value is 0.

Comments

  • BeanBean Posts: 8,129
    edited 2007-12-27 18:53
    Sgn = ~var.7 ' for WORD use ~var.15

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-12-27 18:58
    Hello Bean,

    Is that command something that can be added to a future release of the SX/B compiler? That is a useful BASIC command and would help.

    Robert
  • BeanBean Posts: 8,129
    edited 2007-12-27 20:44
    Robert,
    We could, but I would expect SGN to return either "0", "1" or "-1". So it would only work when assigned to BYTE or WORD variables.

    BTW: ABS is already added.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2007-12-27 21:56
    That sounds like it would be ok. I think that is how it would be used most of the time anyhow. I suppose if someone were to try using it for other types the compiler could just flag it as an error. In the meantime we've got the workaround you've provided.

    Robert
Sign In or Register to comment.