Hey !

I hope this is not taken as a stupid question - I am new to Objective C and trying to get my head around it.

I am trying to translate this JAVA method into Objective C:

My translation thus far to Objective C and a B4i wrapper:

My questions:

1. Is the powf function always available or do I need to import some header file ?

2. I've sometimes seen + instead of - as the first character of the method signature ? What is the difference ?

3. Is this line:

correct ? Or shouldn't it be:

because the full method signature/selector is calculateAccuracy:txPower:rssi: ?

I hope this is not taken as a stupid question - I am new to Objective C and trying to get my head around it.

I am trying to translate this JAVA method into Objective C:

B4X:

```
protected static double calculateAccuracy(int txPower, double rssi) {
if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1.
}
double ratio = rssi*1.0/txPower;
if (ratio < 1.0) {
return Math.pow(ratio,10);
} else {
double accuracy = (0.89976)*Math.pow(ratio,7.7095) + 0.111;
return accuracy;
}
}
```

B4X:

```
#If OBJC
- (double) calculateAccuracy:(int)txPower :(double)rssi
{
if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1.
}
double ratio = rssi*1.0/txPower;
if (ratio < 1.0) {
return powf(ratio,10);
} else {
double accuracy = (0.89976) * powf(ratio,7.7095) + 0.111;
return accuracy;
}
}
#End if
' Returns the estimated distance to a beacon in meters
Sub calculateDistanceFromPowerAndSignalStrength( txPower As Int, rssi As Double) As Double
Dim n As NativeObject = Me
Return n.RunMethod("calculateAccuracy::", Array As Object(txPower, rssi)).AsDouble
End Sub
```

1. Is the powf function always available or do I need to import some header file ?

2. I've sometimes seen + instead of - as the first character of the method signature ? What is the difference ?

3. Is this line:

B4X:

`Return n.RunMethod("calculateAccuracy::", Array As Object(txPower, rssi)).AsDouble`

B4X:

`Return n.RunMethod("calculateAccuracy:txPower:rssi:", Array As Object(txPower, rssi)).AsDouble`

Last edited: