Difference between revisions of "Tutorial"

From Ubcacm
Jump to: navigation, search
 
(Floating Point)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
== Compiling the Program ==
 +
=== C ===
 +
gcc <input.c> -o output -Wall
 +
=== C++ ===
 +
g++ <input.c> -o output -Wall
 +
Note that attempting to compile a C++ file with '''gcc''' will fail with ''' undefined reference to `__gxx_personality_v0''''
 +
 +
'''-Wall''' turns on all compiler warnings, It is not necessary, but often useful to catch silly mistakes in the code.
 +
 +
=== Java ===
 +
javac <input.java>
 +
 
== Data Representation ==
 
== Data Representation ==
 
=== Numbers ===
 
=== Numbers ===
Line 21: Line 33:
 
* This is slow, but infinitely precise.
 
* This is slow, but infinitely precise.
 
==== Floating Point ====
 
==== Floating Point ====
 +
* [http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm Comparing Floating Point numbers]
 +
 
=== Strings ===
 
=== Strings ===
 
=== Structures ===
 
=== Structures ===
 
=== Classes ===
 
=== Classes ===

Latest revision as of 03:52, 18 February 2007

Compiling the Program

C

gcc <input.c> -o output -Wall

C++

g++ <input.c> -o output -Wall

Note that attempting to compile a C++ file with gcc will fail with undefined reference to `__gxx_personality_v0'

-Wall turns on all compiler warnings, It is not necessary, but often useful to catch silly mistakes in the code.

Java

javac <input.java>

Data Representation

Numbers

Boolean

Integers

Fixed Length
  • char: 8 bits in C/C++, 16 bits in Java
  • int: 32 bits
  • long: 32 bits in C/C++, 64 bit in Java
  • long long: 64 bits in C/C++, GCC only. (__int64 in Microsoft C++)

An n-bit signed integer can represent values int the range [-2n-1, 2n-1 - 1].
An unsigned integer can represent values in the range [0, 2n - 1] (Not available in Java)
Values are represented in 2's complement (mod 2n) during overflow.

Division rounds towards 0

    • (-5) / 3 = -1
    • 7 / 3 = 2
    • 1 / 2 = 0
Arbitrary Length

Java has BigInteger

  • This is slow, but infinitely precise.

Floating Point

Strings

Structures

Classes