Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

How to handle powers in c-code generation?

  • To: mathgroup at
  • Subject: [mg40013] How to handle powers in c-code generation?
  • From: at (Christian Ott)
  • Date: Sun, 16 Mar 2003 02:20:21 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Hi there,

I have a problem with generating "nice" c-code in mathematica.
When I use the packages "Format" and "Optimize" to generate the
c-code, the (integer) powers are coded as function calls instead of
multiplications (e.g. pow(x,2.) instead of x*x). These function calls
are obviously quite ineffective in many cases.

Here is a simple example of my problem:
Mathematica Input:
  << Format'
  << Optimize'
  CAssign[x^2, AssignOptimize -> False, OptimizePower -> Binary]

Mathematica Output: pow(x,2.)
Desired Output: x*x

I thought that the option "OptimizePower -> Binary" would be
sufficient to get an output of the form "x*x".
Is there another option that I should use in the CAssign call? 
Or is there a better way of generating c-code from mathematica?

thanks in advance,

  • Prev by Date: Re: Summations with Primes
  • Next by Date: Re: This should evaluate to zero
  • Previous by thread: Functions with multiple groups of arguments? [David Park?]
  • Next by thread: Re: How to handle powers in c-code generation?