Giter Club home page Giter Club logo

gm's Introduction

minecraft floating point arithmetic

a basic utiltiy pack to do math with floats and/or doubles

2 input functions

these functions all require the arguments {x:(number),y:(number)} and ouput the result to the storage gm:io out as well as returning the result as an int

gm:add

does x + y

gm:subtract

does x - y

gm:multiply

does x * y

gm:divide

this has 2 different sets of fuctionality

when specifying x as a number

does x / y

when specifying x as an array of numbers (will only divide up to the first 3 numbers in the array)

does [0] / y, [1] / y, [2] / y

outputs the resulting numbers in an array in the default output location and returns the length of the outputted array

gm:modulo

does x % y

implementation of fmod. fails if y is 0

gm:distance

gets the distance between x and y

for this operation 2 position arrays must be given instead of single values. If an array is empty or values are unspecified, the values will default to 0

gm:arctan2

does atan2(y, x)

this operation is similar to doing tan⁻¹(y/x), except that -180 ≤ atan2(y, x) ≤ 180. This gives a full 360° result, compared the 180° result of just doing tan⁻¹(y/x)

single input functions

these functions only requires {x:(number)} as an argument

gm:negate

does x * -1

gm:reciprocal

does 1 / x

gm:square

does x^2

gm:sqrt

does √x

gm:sin

does sin(x)

gm:cos

does cos(x)

gm:tan

does tan(x)

also outputs sin to storage gm._temp_:std var1 and cos to storage gm._temp_:std var2

gm:arcsin

does sin⁻¹(x)

-90 ≤ sin⁻¹(x) ≤ 90 where -1 ≤ x ≤ 1

gm:arccos

does cos⁻¹(x)

0 ≤ cos⁻¹(x) ≤ 180 where -1 ≤ x ≤ 1

gm:arctan

does tan⁻¹(x)

-90 ≤ tan⁻¹(x) ≤ 90

gm:round

does round(x)

Rounds x to the nearest integer. 0.5 will round up

gm:floor

does floor(x)

Rounds x down to the nearest integer

gm:ceil

does ceil(x)

Rounds x up to the nearest integer

gm's People

Contributors

gibbsly avatar glitchlesscode avatar

Stargazers

DURUMI avatar Oli avatar Dahesor avatar Vincent Hébert avatar  avatar phaic avatar Ciro García Belmonte avatar AmericanBagel avatar Ryan / GFunction avatar  avatar lullaby avatar  avatar std::_Rb_tree avatar Stefan van der Velden avatar Afro avatar  avatar NickAc avatar Stöpa avatar Brunon Blok avatar  avatar  avatar  avatar Felix avatar  avatar Giacomo Botti avatar CKenJa avatar  avatar Pipifax (mit der Lupe 🔎) avatar Erwan Dayot avatar Daniel Weber avatar David J. Kowalk avatar

Watchers

Stefan van der Velden avatar  avatar Ciro García Belmonte avatar  avatar

gm's Issues

Mod operator

Could you add a function that takes in two macros x and y and it returns the remainder of x divided by y.

manage the version on modrinth

would it be possible to make this to a version to publish to modrinth? as its a handy lib datapack many others would find useful
to have me mange the modrinth page, if you have a modrinth account you can or i can if you dont want to have one

modrinth.com/datapack/{name}

Enhancement: Add IMP

Enhancement:

IMP is used fairly often in datapack development. It may allow for easier usability of this datapack to implement IMP into GM (Especially IMP-DOC). Some people may find this useful, considering this datapack really is mainly meant to be a module which exposes an easy API to use.

One small caveat to implementing this is that IMP-DOC currently has no specification for macros, which are widely used in this datapack. However, to resolve this, I propose the following:

Function annotation @macro

This annotation only has one form:

#> namespace:path/to/function
#
# An imaginary example function.
#
# @macro
#   macro_name: type
#      Macro description

So, for example:

#> gm:arctan2
#
# Gets the arctangent of y/x
#
# @macro
#   x: float | double
#      The denominator of the ratio
#   y: float | double
#      The numerator of the ratio

If you think that adding IMP standards into this datapack would be good, let me know, I'm willing to put in a PR for that.

suggestion: distance2 operator

Pretty simple, just a gm:distance operator but doesn't find the square root of the distance. basically just returns x^2 + y^2 to reduce computation when you don't need the actual distance in e.g. comparisons.

Decimal zeros missing after division

Description

When dividing one base-10 number by another base-10 number, if the result number has any zeros in the decimal part, they don't appear in the num array for some reason.
For example, dividing number 2.202 (num:[2,2,0,2],dec:3,pol:1,base:10) by 2.0 (num:[2,0],dec:1,pol:1,base:10) results in a number 1.11 and not 1.101.

Screenshots

image
2.202 / 2.0 is 1.101, while the other digits are correct, zeros appear to be missing

image
3.141592 / 2.0 is 1.570796

How to reproduce

  • Create a new minecraft world with the datapack
  • Call arr_math:setup
  • Run /data modify storage arr_math:in var1 set value {dec:3,num:[2,2,0,2],pol:1,base:10}
  • Run /data modify storage arr_math:in var2 set value {dec:1,num:[2,0],pol:1,base:10}
  • Call arr_math:divide
  • Run /data get storage arr_math:main out

I know the work on the pack might be discontinued, but I'm really hoping for a fix, because otherwise the pack is a treasure :>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.