Chapter 6. Ints, Floats, and Math

Table of Contents
6.1. Types of Numbers in LPC
6.2. Converting Between Number Types
6.3. Operations on Numbers in LPC
6.4. Math Functions in LPC

Math is really useful. No, seriously. All those math teachers that you had that said, "math is important!" were totally right. On a mud where we're simulating the world with objects that have properties and stats, many things are simulated using math. When we talk about math here, we're talking about mostly about algebra and trigonometry.

This chapter covers various math things in LPC: functions, operations, how to deal with int vs. float, and some basic equation structures.

6.1. Types of Numbers in LPC

In LPC, there are two types of variables that hold number-oriented values: int and float. Floats are sometimes referred to as doubles or reals--for the purposes of LPC you might as well use the three terms interchangeably.

ints or integers are whole numbers with no precision. Examples of ints: -20, 0, 1, 40, 1000000, ...

floats are numbers that have precision. Examples of floats: -20.3, 0.40490, 1.0, 40.3930293, 1000.39302, ...

Why have two different types of numbers? The reason is that ints are "simpler" and easier to deal with, but floats have precision. If you're doing any calculations that require precision, then you should convert your operands into floats before performing the calculation.

For example:

  10 / 3     = 3           // division with ints
  10.0 / 3.0 = 3.333333    // division with floats

This might be a trivial example, but there's a world of difference between 3 and 3.333333.

FIXME - add more examples here