Quantcast
Channel: Hacker News
Viewing all articles
Browse latest Browse all 25817

Emacs org-mode examples and cookbook

$
0
0

C code is handled a little differently, as it must be compiled and run.

This block:

#+HEADERS: :includes <math.h> :flags -lm #+HEADERS: :var x=1.0 :var y=4.0 :var z=10.0#+BEGIN_SRC C :exports both
double pi = 4*atan(1);
double r, theta, phi;
r = sqrt(x*x+y*y+z*z);
theta = acos(z/r) * 180.0/pi;
phi = atan2(y,x) * 180.0/pi;
printf("%f %f %f", r, theta, phi);#+END_SRC

Generates, compiles, and runs this C code:

#include<math.h>doublex = 1.000000;doubley = 4.000000;doublez = 10.000000;intmain() {doublepi = 4*atan(1);doubler, theta, phi;
r = sqrt(x*x+y*y+z*z);
theta = acos(z/r) * 180.0/pi;
phi = atan2(y,x) * 180.0/pi;
printf("%f %f %f", r, theta, phi);return 0;
}

which results in:

#+RESULTS:: 10.816654 22.406871 75.963757

So the final result looks like this when evaluated and exported:

doublepi = 4*atan(1);doubler, theta, phi;
r = sqrt(x*x+y*y+z*z);
theta = acos(z/r) * 180.0/pi;
phi = atan2(y,x) * 180.0/pi;
printf("%f %f %f", r, theta, phi);
10.816654 22.406871 75.963757

There is a trick to multiple includes: they must be passed as elisp lists, for example:

#+BEGIN_SRC C :includes '(<math.h> <time.h>)

Viewing all articles
Browse latest Browse all 25817

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>