Skip to content

ceil

Returns the smallest integer not less than x.

Syntax

ceil(x) (init-, control-, or audio-rate arg allowed)
ceil(k/i[]) (k- or i-arrays )

where the argument within the parentheses may be an expression. Value converters perform arithmetic translation from units of one kind to units of another. The result can then be a term in a further expression.

Examples

Here is an example of the ceil opcode. It uses the file ceil-modern.csd.

Example of the ceil opcode.
<CsoundSynthesizer> 
<CsOptions> 
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too

</CsOptions> 
<CsInstruments> 

sr = 44100
ksmps = 32
nchnls = 2

instr 1 
  num:i = p4 
  iceil = ceil(inum) 
  print(iceil)
endin 

</CsInstruments> 
<CsScore> 

i 1 0 0.01 1 
i . + .    0.999999 
i . . .    0.000001 
i . . .    0 
i . . .   -0.0000001 
i . . .   -0.9999999 
i . . .   -1 
e 
</CsScore> 
</CsoundSynthesizer> 

Here is an example of the ceil opcode. It uses the file ceil.csd.

Example of the ceil opcode.
<CsoundSynthesizer> 
<CsOptions> 
; Select audio/midi flags here according to platform
; Audio out   Audio in    No messages
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too

</CsOptions> 
<CsInstruments> 

sr = 44100
ksmps = 32
nchnls = 2

instr 1 

inum = p4 
iceil = ceil(inum) 
print iceil 

endin 

</CsInstruments> 
<CsScore> 

i 1 0 0.01 1 
i . + .    0.999999 
i . . .    0.000001 
i . . .    0 
i . . .   -0.0000001 
i . . .   -0.9999999 
i . . .   -1 
e 
</CsScore> 
</CsoundSynthesizer> 

Its output should include lines like:

instr 1:  iceil = -1.000
instr 1:  iceil = 1.000
instr 1:  iceil = 1.000
instr 1:  iceil = 1.000
instr 1:  iceil = 0.000
instr 1:  iceil = 0.000
instr 1:  iceil = 0.000

Here is another example of the ceil opcode. It uses the file ceil-2-modern.csd.

A second example of the ceil opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac  -d    ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o ceil-2.wav -W ;;; for file output any platform

; By Stefano Cucchi - 2020

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1
  dur:i = p3
  cps:k = 100
  car:k = 1
  mod:k = p4

  ndx:k = poscil(30, 0.25/dur, 1)
  ndx = ceil(ndx)

  sig:a = foscili(0.5, cps, car, mod, ndx, 1)
  outs(sig, sig)
endin
</CsInstruments>
<CsScore>

f 1 0 16384 10 1

i 1 0 10 1.5    
e
</CsScore>
</CsoundSynthesizer>

Here is another example of the ceil opcode. It uses the file ceil-2.csd.

A second example of the ceil opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac      ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o ceil-2.wav -W ;;; for file output any platform

; By Stefano Cucchi - 2020

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1

kcps = 100
kcar = 1
kmod = p4

kndx oscil 30, .25/p3, 1
kndx ceil kndx

asig foscili .5, kcps, kcar, kmod, kndx, 1
     outs asig, asig

endin
</CsInstruments>
<CsScore>

f 1 0 16384 10 1

i 1 0 10 1.5    
e
</CsScore>
</CsoundSynthesizer>

Here is an example for the rounding-group, comparing the different rounding opcodes. It uses the file rounding-group-modern.csd.

Example of the rounding group.
<CsoundSynthesizer>
<CsOptions>
-odac       ;   
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32

; by tgrey 2020
instr 1
  LoopStart:i = p4
  LoopEnd:i   = p5
  Offset:i    = p6

  Count:i = init(LoopStart)

  if LoopStart < LoopEnd then            ; loop going up
    while Count <= LoopEnd do
      Val:i = Count + Offset
      Round:i = round(Val)
      Int:i = int(Val)
      Floor:i = floor(Val)
      Ceil:i = ceil(Val)
      print(Val, Round, Int, Floor, Ceil)
      Count += 1             
    od
  elseif LoopEnd < LoopStart then        ; loop going down
    while Count >= LoopEnd do
      Val = Count + Offset
      Round = round(Val)
      Int = int(Val)
      Floor = floor(Val)
      Ceil = ceil(Val)
      print(Val, Round, Int, Floor, Ceil)
      Count -= 1             
    od
  endif
endin
</CsInstruments>
<CsScore>
i1 0   0.1 0  10 0.5
i1 0.2  .1 0 -10 0.5
e
</CsScore>
</CsoundSynthesizer>

Here is an example for the rounding-group, comparing the different rounding opcodes. It uses the file rounding-group.csd.

Example of the rounding group.
<CsoundSynthesizer>
<CsOptions>
-odac       ;   
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32

; by tgrey 2020
instr 1

iLoopStart = p4
iLoopEnd   = p5
iOffset    = p6

iCount init iLoopStart


if(iLoopStart<iLoopEnd) then            ; loop going up
        while iCount <= iLoopEnd do
                iVal = iCount+iOffset
                iRound = round(iVal)
                iInt = int(iVal)
                iFloor = floor(iVal)
                iCeil = ceil(iVal)
                print iVal, iRound, iInt, iFloor, iCeil
                iCount = iCount + 1             
        od

elseif(iLoopEnd<iLoopStart) then        ; loop going down
        while iCount >= iLoopEnd do
                iVal = iCount+iOffset
                iRound = round(iVal)
                iInt = int(iVal)
                iFloor = floor(iVal)
                iCeil = ceil(iVal)
                print iVal, iRound, iInt, iFloor, iCeil
                iCount = iCount - 1             
        od
endif
endin
</CsInstruments>
<CsScore>
i1 0 .1 0 10 .5
i1 .2 .1 0 -10 .5
e
</CsScore>
</CsoundSynthesizer>

See also

Mathematical Functions

Credits

Author: Istvan Varga
New in Csound 5
2005