Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Is there a way to calculate the absolute value? :v

A topic by MrrPalta created 59 days ago Views: 102 Replies: 1
Viewing posts 1 to 2

Is there a way to calculate the absolute value? my only question

Developer(+1)

If you apply it to a single number, the "mag" primitive gives the absolute value:

mag -23    # 23
mag 5      # 5

In the more general case, "mag" gives the magnitude of a vector of numbers, also known as the Euclidean distance:

mag 3,4    # 5
mag 3,7    # 7.615773

If you want the absolute value of each element in a list, you can "push" mag down to each number with @:

mag @ -3,4,-5   # (3,4,5)