swift - Why CFloat and CDouble?? func addNewValue(newVal: CFloat, atTime time: CDouble) -> CFloat {} -


i converted

-(float) addnewvalue:(float) newval attime:(double) time { 

to

func addnewvalue(newval: cfloat, attime time: cdouble) -> cfloat {} 

there no errors don't know why works. why float , double become cfloat , cdouble?

there no errors with:

func addnewvalue(newval: float, attime time: double) -> float {} 

so supposed use?

full code

let maxperiod:double = 1.5 let minperiod:double = 0.1 let invalidentry = -100 let maxperiodstostore = 20 let averagesize:int = 20   class detector {      let session = avcapturesession()     var camera : avcapturedevice?      var upvals = [averagesize]     var downvals = [averagesize]     var upvalindex: int?     var downvalindex: int?      var lastval: float?     var periodstart: float?     var periods = [maxperiodstostore]      var periodtimes = [maxperiodstostore]      var periodindex: int?     var started: bool?     var freq: float?     var average: float?      var wasdown: bool?       func reset() {           var i:int = 0; < maxperiodstostore; i++ {             periods[i] = invalidentry         }         var i:int = 0; < averagesize; i++ {             upvals[i] = invalidentry             downvals[i] = invalidentry         }         freq = 0.5         periodindex = 0         downvalindex = 0         upvalindex = 0     }      // question regarding function      func addnewvalue(newval: float, attime time: double) -> float {     // keep track of number of values above , below 0     if newval > 0 {     upvals[upvalindex!] = newval     upvalindex!++     if upvalindex >= averagesize {     upvalindex = 0     }     }     if newval < 0 {     downvals[downvalindex!] -= newval     downvalindex!++     if downvalindex! >= averagesize as! int {     downvalindex = 0     }     }     // work out average value above 0     var count: float     var total: float     var i=0; < averagesize; i++ {     if upvals[i] != invalidentry {     count++     total += upvals[i]     }     }     var averageup = total/count     // , average value below 0     count=0;     total=0;     var i=0; < averagesize; i++ {     if downvals[i] != invalidentry {     count++     total+=downvals[i]     }     }     var averagedown = total/count      // new value down value?     if newval < (-0.5*averagedown) {     wasdown = true     }      // new value value , in down state?     if (newval >= (0.5*averageup) && (wasdown) != nil) {     wasdown = false      // work out difference between , last time happenned     if (time - periodstart) < maxperiod && (time - periodstart) > minperiod {     periods[periodindex]=time-periodstart     periodtimes[periodindex]=time     periodindex++     if periodindex >= maxperiodstostore {                 periodindex = 0     }     }     // track when transition happened     periodstart = time     }     // return or down     if newval < (-0.5*averagedown) {     return -1     } else if newval > (0.5*averageup) {     return 1     }     return 0     } 

so supposed use?

float , double. terms cfloat , cdouble merely typealiases (synonyms) these, there no point using them; there merely compatibility.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -