File: test2p.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (19 lines) | stat: -rw-r--r-- 384 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function [y]=test2p(n)
//!
// Copyright INRIA
[o,i]=argn(0);
   if i < 1 then error(58); end;
   if type(n) <>1 then error(53,1); end;
   if size(n) <> [1 1] then error(89,1); end;
//
   if n < 1 then y=1;
   else
     p=log(n)/log(2);
     rp=1 - p + int(p);
     if rp < 1e-7 then p=int(p)+1; else p=int(p); end;
     r=n-2**p;
     if r <= 1e-7 then y=0; else y=1; end;
   end;