The super
keyword in Solidity gives access to the immediate parent contract from which the current contract is derived. When having a contract A
with a function f()
that derives from B
which also has a function f()
, A
overrides the f
of B
. That means that myInstanceOfA.f()
will call the version of f
that is implemented inside A
itself, the original version implemented inside B
is not visible anymore. The original function f
from B
(being A
's parent) is thus available inside A
via super.f()
. Alternatively, one can explicitly specifying the parent of which one wants to call the overridden function because multiple overriding steps are possible as exemplified in the example below:
pragma solidity ^0.4.5;
contract C {
uint u;
function f() {
u = 1;
}
}
contract B is C {
function f() {
u = 2;
}
}
contract A is B {
function f() { // will set u to 3
u = 3;
}
function f1() { // will set u to 2
super.f();
}
function f2() { // will set u to 2
B.f();
}
function f3() { // will set u to 1
C.f();
}
}
You can check with the code below that this line:
uint256 roundValue = SafeMath.ceil(_value, basePercent);
If your value _value
is higher than basePercent
, roundValue
will be the number rounded on the hundred, otherwise the _value
will be basePercent
always.
Example: input = 1
--> roundValue = 100
Example: input = 4111
--> roundValue = 4200
Code:
Supposing a SafeMath library
like the following:
pragma solidity ^0.5.0;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
function ceil(uint256 a, uint256 m) internal pure returns (uint256) {
uint256 c = add(a,m);
uint256 d = sub(c,1);
return mul(div(d,m),m);
}
}
And the onePercent
function:
import "./SafeMath.sol";
contract Percentage{
uint256 public basePercent = 100;
function onePercent(uint256 _value) public view returns (uint256) {
uint256 roundValue = SafeMath.ceil(_value, basePercent);
uint256 onePercent = SafeMath.div(SafeMath.mul(roundValue, basePercent), 10000);
return onePercent;
}
}
Best Answer
It's a regular inline if statement, found in many modern languages.
It means "set the value
q
to be eithera
orb
- decided whetherp % 2 != 0
givestrue
orfalse
.This can be rewritten as: