Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions authors.textile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ _The following people are totally rad and awesome because they have contributed
* Steven Reid _steven @ reidnorthwest . com_
* David Moulton _dave@themoultons.net_
* Sebastian Slomski _sebastian@simple-systems.org_
* Aaron Weinberger _aw9994@cs.ship.edu_
* ...You! What are you waiting for? Check out the <a href="/contributing">contributing</a> section and get cracking!


Expand Down
49 changes: 49 additions & 0 deletions chapters/math/constants.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
layout: recipe
title: Math Constants
chapter: Math
---

h2. Problem

You need to use common mathematical constants like pi or e.

h2. Solution

Use Javascript's Math object to provide commonly needed mathematical constants.

{% highlight coffeescript %}
Math.PI
# => 3.141592653589793

# Note: Capitalization matters! This produces no output, it's undefined.
Math.Pi
# =>

Math.E
# => 2.718281828459045

Math.SQRT2
# => 1.4142135623730951

Math.SQRT1_2
# => 0.7071067811865476

# Natural log of 2. ln(2)
Math.LN2
# => 0.6931471805599453

Math.LN10
# => 2.302585092994046

Math.LOG2E
# => 1.4426950408889634

Math.LOG10E
# => 0.4342944819032518

{% endhighlight %}

h2. Discussion

For another example of how a math constant is used in a real world problem, refer to the <a href="http://coffeescriptcookbook.com/chapters/math/radians-degrees">'Converting Radians and Degrees'</a> section of this Math chapter.