Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Math.sign doesn't exist!!!

Return to Member Forum

  • Author
    Posts
    • #1221102

      Greetings from Vancouver,

      It appears ExtendScript doesn’t have full Math support.
      I’m simply trying to use Math.sign() and it errors out.

      View post on imgur.com

      Am I missing something?

      Cheers,

      Antoine

    • #14323337

      Yes, Math.sign does not exist in ExtendScript.

      Math.sign and other such functions, for example String.startsWith, Array.indexOf have been added to newer versions of ECMAScript, and are available in web browsers, but not in ExtendScript.

      I tend to use polyfills for such cases.

      From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign

      if (!Math.sign) {
      Math.sign = function(x) {
      // If x is NaN, the result is NaN.
      // If x is -0, the result is -0.
      // If x is +0, the result is +0.
      // If x is negative and not -0, the result is -1.
      // If x is positive and not +0, the result is +1.
      return ((x > 0) – (x < 0)) || +x;
      };
      }

      Add this polyfill, and your code should work fine.

      Thanks,
      MT

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Forum Ads