[CustomAPI] Math expressions

The problem is the Twitch variable for followers uses a comma which is actually why I was asking for the option to strip them. :wink:

Sample code if commas were not a problem:
$(urlfetch ttp://twitch.center/customapi/math?expr=1000000-$(twitch channelname "{{followers}}"))

You can actually strip commas with the $(eval) variable, though it will get rather wordy.

$(urlfetch http://twitch.center/customapi/math?expr=1000000-$(eval "$(twitch channelname "{{followers}}")".replace(/,/g, "")))

That will strip the commas before sending them to the variable.

Edit: You could actually do this with just eval if you wanted. Like so:

$(eval 1000000-"$(twitch channelname "{{followers}}")".replace(/,/g, ""))

Finally got around to messing with that command again. I had no idea $(eval) was a thing! I’ll certainly have to keep that one in mind for some future weird commands.

Thanks for the tip, Slikrick!

well it’s seem have problem in the point part

the correct display will be 2500.68743,right?

So could this math API do for example 10 minus 15%? I am a creative streamer and it would be handy to work out the shrinkage rate for my clay while I am making on stream.

Assuming you mean you lose 15% of 10, then that would just be the math of 10 - (10 * .15) unless im not understanding what you mean exactly.

yeah that’s what I meant. Thank you

Can you correct this bug?

There is an error with the Log function. Any results that have a 0 after the decimal would remove the decimal point and the 0. Example:
http://twitch.center/customapi/math?expr=log10(3.1622*32) should give 2.005139, but it gives 25139.

I guess this is actually a bug for any answer that has 0’s after the decimal point. (example: 0.1*0.1 gives 010000)

Could catch, should be fixed now.

I’m having an issue with the Custom Math API.

I am trying to get the sum of two numbers. I believe I am using the function correctly, I can get other modifiers to work i.e. multiplication, subtraction, etc.


$(urlfetch http://twitch.center/customapi/math?expr=5+4)

$(urlfetch http://twitch.center/customapi/math?expr=5-4)

Any ideas?

You need to URL encode your query.

* URL encoded is *
- URL encoded is -
+ URL encoded is %2B

$(urlfetch http://twitch.center/customapi/math?expr=5%2B4)

Alternatively you can just use Nightbot’s eval variable to get the sum of two numbers:
$(eval 5+4)

1 Like

I did not know about the eval command. Thank you very much, this works perfectly for what I am doing.

tan(2pi) = 0
pi) = 1/0 = ???
BUT api says
tan(2pi) = -0
pi) = -4082809838298842.5
1/-0 = ???

that is a problem i think…

@Kodirov There is nothing really wrong about any of those mathematical statements.

If you graph the function f(x)=1/tan(2x) you’ll see that as x approaches π from the left, the function explodes towards -infinity. That tells you that 1/tan(2π) is undefined.

But because π is an irrational number, the API can only approximate its value. It seems that the API approximates the value of π just slightly below its actual value, therefore 1/tan(2π) returns a very large negative value, but not infinity/-infinity/undefined.


Right, technically, 1/0 = ∞, but here tan(2/pi), due to precision errors, returns 0.0000000000000002, and therefore you end up with a really large number instead of infinity.

Oh right. I forgot that numbers are approximate.
My bad. Sorry.