-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Open
Labels
Description
π Issue Category
- Feature Request β¨
π Issue Summary
Add Euler's number (E
) as a new mathematical constant in p5.js
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
Feature request details
πΉ Description
Euler's number (E
, approximately 2.71828) is a fundamental mathematical constant representing the base of natural logarithms. It plays a crucial role in:
- Exponential growth and decay models
- Compound interest calculations
- Probability distributions (e.g., Poisson, exponential)
- Calculus and differential equations
- Natural phenomena simulations
p5.js currently provides several mathematical constants (PI
, TWO_PI
, HALF_PI
, TAU
), but notably lacks E
. Adding this constant would:
- Complete the set of essential mathematical constants
- Eliminate the need for users to define
E
manually or useMath.E
- Maintain consistency with the library's existing constant naming conventions
- Enhance p5.js's utility for mathematical visualizations and educational projects
πΉ Proposed Implementation
1. Add constant definition in src/core/constants.js
:
/**
* The mathematical constant Euler's number (e), the base of natural logarithms.
* It is approximately equal to 2.71828.
*
* @property {Number} E
* @final
* @example
* <div><code>
* // Calculate exponential growth
* let growth = E ** 2;
* text('eΒ² = ' + growth.toFixed(4), 10, 50);
* </code></div>
*/
export const E = Math.E;