class_notes7

C example gcc lm o prog1out prog1c math library

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return data type double • Compiling programs with math library functions – Compile command must include the option –lm – Example: gcc –lm prog1.c – Example: gcc –lm –o prog1.out prog1.c Math Library Functions From Fig. 5.2 in book – commonly used math library functions: Function sqrt(x) exp(x) log(x) log10(x) fabs(x) ceil(x) floor(x) Description square root of x exponential function ex natural log of x [ ln(x) ] log (base 10) of x [ log10(x) ] absolute value of x rounds x to the smallest integer not less than x rounds x to the largest integer not greater than x Example sqrt( 900.0 ) is 30.0 sqrt( 4.0 ) is 2.0 exp( 1.0 ) is 2.718282 exp( 2.0 ) is 7.389056 log( 2.718282 ) is 1.0 log( 7.389056 ) is 2.0 log10( 1.0 ) is 0.0 log10( 100.0 ) is 2.0 fabs( 3.5 ) is 3.5 fabs( -2.3 ) is 2.3 ceil( 9.2 ) is 10.0 ceil( -7.8 ) is -7.0 floor( 9.2 ) is 9.0 floor( -7.8 ) is -8.0...
View Full Document

Ask a homework question - tutors are online