ceil

ceil — Returns the smallest integer not less than x

Description

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.csd.

Example 120. Example of the ceil opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<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 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.csd.

Example 121. 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.csd.

Example 122. 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

abs, exp, int, log, log10, i, sqrt

Credits

Author: Istvan Varga
New in Csound 5
2005