13.07.2015 Views

Turbo Basic

Turbo Basic

Turbo Basic

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Numbers in <strong>Turbo</strong>·<strong>Basic</strong>The care and feeding of numbers constitutes an important part of every programmingsystem.<strong>Turbo</strong> <strong>Basic</strong>, in keeping with the BASIC tradition, has been designedto let you pretty much ignore technical considerations about internal numeric handling.If you never give a thought to such matters as calculation speed, precision,and memory requirement, your. programs will still. probably work as you expect.However, an understanding of the underlying issues will help you write ·programsthat are faster, more accurate, and require less memory.For efficiency, <strong>Turbo</strong> <strong>Basic</strong> stores and processes numbers in four different forms;that is, it supports four unique numeric "types": integers, long integers, singleprecisionfloating point, and double-precision floating point.IntegersThe simplest and fastest numbers rattling around inside <strong>Turbo</strong> <strong>Basic</strong> programs areintegers. To <strong>Turbo</strong> <strong>Basic</strong>, an integer is a number with no decimal point (whatmathematicians callwhole numbers} within the range -32,768 to 32,767. Thesevalues stem from the underlying 16-bit representation of integers: 32,768 is 2 15 •Although this range limits the usefulness of integers, there are almost certainly afew variables in every program you will write (such as the counters in FOR/NEXT .loops) that can function within these constraints. If so, using integers producesextremely fast and compact code. Your computer is uniquely comfortable performinginteger arithmetic (for example, it does it fast), and each number requires only2 bytes of memory.The Overflow debugging switch in the Options menu lets you create programsthat automatically check and report incidences of integer variable overflow.Umg IntegersIn a significant extension to Interpretive BASIC, <strong>Turbo</strong> <strong>Basic</strong> supports a numerictype known as long integers. To avoid round-off errors, long integers are the perfectdata type for financial applications. Like regular integers, long integers cannot containdecimal points. Unlike integers, however, they span a vast range, from- 2,147,483,648 to + 2,147,483,647 (-2 31 to 2 3 \ or - 2 billion to + 2 billion). Thedown side of this expanded range is that long integers· require 4 bytes of storage,and calculating with them takes longer than with integers;<strong>Turbo</strong> <strong>Basic</strong>: The Language 65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!