Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.soft-sys.math.mathematica > #16942
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail |
|---|---|
| From | Daniel <dosadchy@its.jnj.com> |
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Compiler output type |
| Date | Tue, 13 May 2014 02:26:32 +0000 (UTC) |
| Sender | steve@smc.vnet.net |
| Approved | Steven M. Christensen <steve@smc.vnet.net>, Moderator |
| Message-ID | <lkrvso$25$1@smc.vnet.net> (permalink) |
| Lines | 26 |
| Organization | Time-Warner Telecom |
| NNTP-Posting-Date | 13 May 2014 02:32:53 GMT |
| NNTP-Posting-Host | 18471be1.news.twtelecom.net |
| X-Trace | DXC=O0aS1Y9oQMCcn?\5K_?h9OC_A=>8kQj6M;[h;PUXBgbDCWN^lO<@<PLEFiONJ7[GoFLm2j?[494ZO |
| X-Complaints-To | abuse@twtelecom.net |
| Xref | csiph.com comp.soft-sys.math.mathematica:16942 |
Show key headers only | View raw
This will do the trick:
collatz = Compile[{{n, _Integer}}, If[EvenQ[n], n/2, 3 n + 1]//Round]
I think that the problem is with n/2. Although the result is guaranteed to be integer, the compiler cannot analyze the code and know it, so the output is set to Real.
> Some compiled functions yield reals even if the
> e 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 Daniel <dosadchy@its.jnj.com> - 2014-05-13 02:26 +0000
csiph-web