Skip to content

Add sin, cos and tan trigonometric functions - #2065

Open
lemm-e wants to merge 1 commit into
botlabs-gg:devfrom
lemm-e:trig-func
Open

Add sin, cos and tan trigonometric functions#2065
lemm-e wants to merge 1 commit into
botlabs-gg:devfrom
lemm-e:trig-func

Conversation

@lemm-e

@lemm-e lemm-e commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This PR adds sin, cos and tan trigonometric functions from the math package.

@lemm-e lemm-e changed the title Add sin, cos and tan trignometric functions Add sin, cos and tan trigonometric functions Jun 1, 2026
switch arg.(type) {
case int, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64:
return math.Sin(ToFloat64(arg))
default:

@l-zeuch l-zeuch Jun 1, 2026

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.

This currently does not account for complex numbers, but they're also valid in custom commands (do not ask how I know...). The sine of a complex number can be defined as

$$ \sin (a+bi) = \sin a \cdot \cosh b + i \cos a \cdot \sinh b $$

I'd suggest we

  1. add complex numbers as a valid input to these function as well using the definition above, or
  2. also add the hyperbolic functions.

Personally I'm leaning towards both; the hyperbolic functions may have some interesting properties as well and given that we're already here, why not.

}
}

func tmplCos(arg interface{}) float64 {

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.

The complex cosine can be defined as

$$ \cos (a+bi) = \cos a \cdot \cosh b - i \sin a \cdot \sinh b $$

}
}

func tmplTan(arg interface{}) float64 {

@l-zeuch l-zeuch Jun 1, 2026

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.

Similarly,

$$ \tan (a + bi) = \frac{\sin (a+bi)}{\cos (a+bi)} = \frac{\sin a \cdot \cosh b + i \cos a \cdot \sinh b}{\cos a \cdot \cosh b - i \sin a \cdot \sinh b} $$

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