Groups | Search | Server Info | Login | Register
Groups > comp.soft-sys.math.mathematica > #16943
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Compiler output type |
| Date | 2014-05-13 02:26 +0000 |
| Message-ID | <lkrvtc$2c$1@smc.vnet.net> (permalink) |
| References | <20140512044303.976186A56@smc.vnet.net> |
| Organization | Time-Warner Telecom |
collatz = Compile[{{n, _Integer}}, If[EvenQ[n], n/2, 3 n + 1] //
IntegerPart];
collatz2 = Compile[{{n, _Integer}}, If[EvenQ[n], n/2, 3 n + 1] // Round];
m = 1000000;
Timing[t1 = Table[collatz[n], {n, m}];]
{0.291132, Null}
Timing[t2 = Table[collatz2[n], {n, m}];]
{0.322116, Null}
Timing[t3 = Table[If[EvenQ[n], n/2, 3 n + 1], {n, m}];]
{2.352646, Null}
t1 == t2 == t3
True
Bob Hanlon
On Mon, May 12, 2014 at 12:43 AM, Harvey P. Dale <hpd@hpdale.org> wrote:
> Some compiled functions yield reals even if the input and
> necessary output are integers. How can I force the output to be an integer
> rather than a real in such cases? To be clear, not all compiled program
> output produces reals; some compiled programs, given integer inputs,
> produce integer outputs. But some do not. An example is:
>
> collatz = Compile[{{n, _Integer}}, If[EvenQ[n], n/2, 3 n + 1]]
>
> It produces real rather than integer output, and I'd like to force integer
> output if possible.
>
> Thanks
>
> Best,
>
> Harvey
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar
Re: Compiler output type Bob Hanlon <hanlonr357@gmail.com> - 2014-05-13 02:26 +0000
csiph-web