Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Sass中的幂运算_Ruby_Sass_Exponent - Fatal编程技术网

Ruby Sass中的幂运算

Ruby Sass中的幂运算,ruby,sass,exponent,Ruby,Sass,Exponent,在发现Sass没有指数能力之后,我决定创建自己的pow()函数。这是我失败的尝试: @function pow($x,$p) { $u: unit($x); $x: $x / 1#{$u}; $p: round($p); @if $p == 0 { @return 0; } @else if $p == 1 { @return $x; } @else { @for $i from 1 through abs($p) { $x: $x *

在发现Sass没有指数能力之后,我决定创建自己的pow()函数。这是我失败的尝试:

@function pow($x,$p) {
  $u: unit($x);
  $x: $x / 1#{$u};
  $p: round($p);
  @if $p == 0 {
    @return 0;
  } @else if $p == 1 {
    @return $x;
  } @else {
    @for $i from 1 through abs($p) {
      $x: $x * $x;
    }
  }
  @if $p < 0 {
    $x: 1 / $x;
  }

  @return $x + $u;
}
@函数功率($x,$p){
$u:单位($x);
$x:$x/1{$u};
$p:圆形($p);
@如果$p==0{
@返回0;
}@else如果$p==1{
@返回$x;
}@else{
@从1到abs的$i($p){
$x:$x*$x;
}
}
@如果$p<0{
$x:1/$x;
}
@返回$x+$u;
}
我被困的部分是剥离单元。我知道
12px/1px=12
,但在我的例子中,单位是未知的,
12px/1{unit(12px)}
不起作用,因为它等于
“12px/1px”
(是的,带引号)。
unquote
功能似乎对我不起作用,我不知道为什么


如果你想知道的话,我想剥离单元(并最终返回它们)的原因是因为
12px*12px=144px*px
而不是在Sass中编写
pow
使用Ruby

,但是每个想使用我的mixin使用
pow()
的人都必须使用猴子补丁Sass。。。