Skip to content

add a few macros and functions - #5

Closed
faretek1 wants to merge 0 commit into
goboscript:mainfrom
faretek1:main
Closed

add a few macros and functions#5
faretek1 wants to merge 0 commit into
goboscript:mainfrom
faretek1:main

Conversation

@faretek1

Copy link
Copy Markdown

This pr just adds a few macros/functions that i thought would be useful

  • zfill from python in string.gs - just pad in 0s to the front of a string until it's the given width
  • logb - log with base - not sure which way to put parameters
  • sign macro, (x > 0 - x < 0)
  • atan2, taken from wikipedia
  • dir macro, which is similar to the point to x/y from one of the recipes
  • i added these to the testing project, although there are some false 'positives' due to floating point error

Comment thread math.gs Outdated
@faretek1

Copy link
Copy Markdown
Author

i removed it then

@faretek1
faretek1 requested a review from aspizu March 26, 2025 17:44
@faretek1

faretek1 commented Apr 6, 2025

Copy link
Copy Markdown
Author

bump

Comment thread test/test.gs Outdated
ASSERT_EQ(LOGB(8, 2), 3, "LOGB(8, 2)")
ASSERT_EQ(SIGN(123), 1, "SIGN(123)")
ASSERT_EQ(SIGN(0), 0, "SIGN(0)")
ASSERT_EQ(SIGN(-456), 1, "SIGN(-456)")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be -1?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last one should be. ill change it

@faretek1

faretek1 commented Apr 7, 2025

Copy link
Copy Markdown
Author

I now realise that making a pull request means that one should check through the code for obvious mistakes. i found another issue where the logb macro was tested, but it was previously removed, for example.

i have checked through all the code. I think that I tested it at the time. However, due to floating point error, the test script might not be fully accurate. maybe a rounding to ~3dp would be ideal

@faretek1
faretek1 requested a review from aspizu April 7, 2025 16:48
@faretek1 faretek1 closed this Jul 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants