Floating Point Literals

Floating point literals may be expressed in a variety of formats to simplify the task of expressing different ranges of values.

Rules

  • Cannot start with 0 unless the 0 is followed by a decimal point.
  • Can use 'e' notation to express exponential values (ke±n represents k·10±n).
  • May include a decimal point (should be included when not using 'e' notation).
  • Cannot include commas or spaces.
  • Must use only the digits zero-nine.
  • May be preceded by a minus sign "-".

Examples of Valid Floating Point Literals

2.56e-5 10.4378 48e8 0.5 10f 10.2f

The 'f' in the last two examples is a literal qualifier, described on the next page. It forces the compiler to treat it as a float, which would otherwise be treated as something else:

  • 10 would be treated as an int
  • 10.2 would be treated as a double

We'll see why this is important in the section on operators.

Examples of Invalid Floating Point Literals

0x5Ae-2 02.41 F2.33 0x2.A
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.