SassyBitwise 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -5
- data/lib/SassyBitwise.rb +13 -13
- data/stylesheets/SassyBitwise/api/_bitwise.scss +67 -46
- data/stylesheets/SassyBitwise/helpers/_binary-length.scss +9 -9
- data/stylesheets/SassyBitwise/helpers/_binary-to-decimal.scss +27 -27
- data/stylesheets/SassyBitwise/helpers/_decimal-to-binary.scss +24 -24
- data/stylesheets/SassyBitwise/helpers/_largest-power-of-2.scss +16 -16
- data/stylesheets/SassyBitwise/helpers/_order-args.scss +15 -15
- data/stylesheets/SassyBitwise/helpers/_power.scss +27 -25
- data/stylesheets/SassyBitwise/helpers/_sign.scss +9 -9
- data/stylesheets/SassyBitwise/operators/_and.scss +22 -22
- data/stylesheets/SassyBitwise/operators/_not.scss +10 -10
- data/stylesheets/SassyBitwise/operators/_or.scss +24 -24
- data/stylesheets/SassyBitwise/operators/_shift-left.scss +11 -11
- data/stylesheets/SassyBitwise/operators/_shift-right.scss +11 -11
- data/stylesheets/SassyBitwise/operators/_xor.scss +22 -22
- data/stylesheets/SassyBitwise/validators/_arguments-validator.scss +51 -45
- data/stylesheets/_SassyBitwise.scss +15 -16
- metadata +4 -5
- data/stylesheets/SassyBitwise/validators/_is-number.scss +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b82ee8e952de819d97e3e9d100d4023d23f2da61
|
4
|
+
data.tar.gz: 3ae28fe7d979975646d86bc9c0a1a12292b80a41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b0d9ed7bbd080f53e0602fd789772c6f98b4283d244ff19358b3cc4c6ae01cbd0bce9a3dfd7db8765c232535d6cf55e29eed9b4a1a4e796e7a52f772d5dd3a7
|
7
|
+
data.tar.gz: 456500ff5e3ed88fcc8d356ddcb3f4ab2d99cb651b88fbb75462352bf31dc8e96e9a4978624623ce6554b1d8af8bfa17064b44c38c867fa229b08ea9fd957d2d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
* `1.0
|
4
|
-
* `1.0.
|
5
|
-
* `0.0
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
* `1.1.0`: new API accepting multiple bitwise operation simultaneously
|
4
|
+
* `1.0.1`: fixing important issue in `^`, `|` and `&`
|
5
|
+
* `1.0.0`: stable API, gem release
|
6
|
+
* `0.0.1`: initial commit
|
data/lib/SassyBitwise.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'compass'
|
2
|
-
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
3
|
-
Compass::Frameworks.register('SassyBitwise', :path => extension_path)
|
4
|
-
|
5
|
-
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
6
|
-
# Date is in the form of YYYY-MM-DD
|
7
|
-
module SassyBitwise
|
8
|
-
VERSION = "1.0
|
9
|
-
DATE = "2014-06-
|
10
|
-
end
|
11
|
-
|
12
|
-
module Sass::Script::Functions
|
13
|
-
|
1
|
+
require 'compass'
|
2
|
+
extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
3
|
+
Compass::Frameworks.register('SassyBitwise', :path => extension_path)
|
4
|
+
|
5
|
+
# Version is a number. If a version contains alphas, it will be created as a prerelease version
|
6
|
+
# Date is in the form of YYYY-MM-DD
|
7
|
+
module SassyBitwise
|
8
|
+
VERSION = "1.1.0"
|
9
|
+
DATE = "2014-06-05"
|
10
|
+
end
|
11
|
+
|
12
|
+
module Sass::Script::Functions
|
13
|
+
|
14
14
|
end
|
@@ -1,46 +1,67 @@
|
|
1
|
-
// Bitwise helper function
|
2
|
-
// ---
|
3
|
-
// @param [list] $args: list of parameters
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function bitwise($args) {
|
8
|
-
@if not arguments-validator($args) {
|
9
|
-
@return false;
|
10
|
-
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
1
|
+
// Bitwise helper function
|
2
|
+
// ---
|
3
|
+
// @param [list] $args: list of parameters
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function bitwise($args) {
|
8
|
+
@if not arguments-validator($args) {
|
9
|
+
@return false;
|
10
|
+
}
|
11
|
+
|
12
|
+
$result: null;
|
13
|
+
$operator: null;
|
14
|
+
$not-operator: false;
|
15
|
+
$operators: (
|
16
|
+
'&' : 'and',
|
17
|
+
'|' : 'or',
|
18
|
+
'^' : 'xor',
|
19
|
+
'<<' : 'shift-left',
|
20
|
+
'>>' : 'shift-right'
|
21
|
+
);
|
22
|
+
|
23
|
+
// Loop through all arguments
|
24
|
+
@each $current in $args {
|
25
|
+
|
26
|
+
// If current argument is an operator
|
27
|
+
// Store it while waiting for next value
|
28
|
+
@if map-has-key($operators, $current) {
|
29
|
+
$operator: $current;
|
30
|
+
}
|
31
|
+
|
32
|
+
// If current argument is `not` bitwise operator
|
33
|
+
// Pass $not boolean to true
|
34
|
+
@else if $current == '~' {
|
35
|
+
$not-operator: true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// If current argument is not an operator
|
39
|
+
@else {
|
40
|
+
// If $not is true
|
41
|
+
// Compute not first
|
42
|
+
@if $not-operator {
|
43
|
+
$current: bw-not($current);
|
44
|
+
$not-operator: false;
|
45
|
+
}
|
46
|
+
|
47
|
+
// Then the operation
|
48
|
+
@if $operator {
|
49
|
+
$result: call('bw-' + map-get($operators, $operator), $result, $current);
|
50
|
+
$operator: null;
|
51
|
+
}
|
52
|
+
|
53
|
+
@else {
|
54
|
+
$result: $current;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
@return $result;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
// Alias for `bitwise`
|
64
|
+
// ---
|
65
|
+
@function bw($args) {
|
66
|
+
@return bitwise($args);
|
67
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
// Returns binary length
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: value
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function binary-length($value) {
|
8
|
-
@return str-length(decimal-to-binary($value) + unquote(""))
|
9
|
-
}
|
1
|
+
// Returns binary length
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: value
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function binary-length($value) {
|
8
|
+
@return str-length(decimal-to-binary($value) + unquote(""));
|
9
|
+
}
|
@@ -1,27 +1,27 @@
|
|
1
|
-
// Convert from base 2 to base 10
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: binary to convert
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function binary-to-decimal($value) {
|
8
|
-
$value: $value + unquote('');
|
9
|
-
$result: if(str-slice($value, 1, 1) == "0", 0, 1);
|
10
|
-
|
11
|
-
@for $i from 2 through str-length($value) {
|
12
|
-
$c: str-slice($value, $i, $i);
|
13
|
-
|
14
|
-
@if not index("0" "1", $c) {
|
15
|
-
@warn "Not binary.";
|
16
|
-
@return false
|
17
|
-
}
|
18
|
-
|
19
|
-
$result: $result * 2;
|
20
|
-
|
21
|
-
@if $c == "1" {
|
22
|
-
$result: $result + 1
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
@return $result
|
27
|
-
}
|
1
|
+
// Convert from base 2 to base 10
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: binary to convert
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function binary-to-decimal($value) {
|
8
|
+
$value: $value + unquote('');
|
9
|
+
$result: if(str-slice($value, 1, 1) == "0", 0, 1);
|
10
|
+
|
11
|
+
@for $i from 2 through str-length($value) {
|
12
|
+
$c: str-slice($value, $i, $i);
|
13
|
+
|
14
|
+
@if not index("0" "1", $c) {
|
15
|
+
@warn "Not binary.";
|
16
|
+
@return false;
|
17
|
+
}
|
18
|
+
|
19
|
+
$result: $result * 2;
|
20
|
+
|
21
|
+
@if $c == "1" {
|
22
|
+
$result: $result + 1;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
@return $result;
|
27
|
+
}
|
@@ -1,24 +1,24 @@
|
|
1
|
-
// Convert from base 10 to base 2
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: decimal to convert
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function decimal-to-binary($value) {
|
8
|
-
$largest: largest-power-of-2($value);
|
9
|
-
$result: 0;
|
10
|
-
|
11
|
-
@while $largest >= 1 {
|
12
|
-
@if $value - $largest >= 0 {
|
13
|
-
$value: $value - $largest;
|
14
|
-
$result: $result * 10 + 1
|
15
|
-
}
|
16
|
-
@else {
|
17
|
-
$result: $result * 10
|
18
|
-
}
|
19
|
-
|
20
|
-
$largest: $largest / 2
|
21
|
-
}
|
22
|
-
|
23
|
-
@return $result
|
24
|
-
}
|
1
|
+
// Convert from base 10 to base 2
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: decimal to convert
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function decimal-to-binary($value) {
|
8
|
+
$largest: largest-power-of-2($value);
|
9
|
+
$result: 0;
|
10
|
+
|
11
|
+
@while $largest >= 1 {
|
12
|
+
@if $value - $largest >= 0 {
|
13
|
+
$value: $value - $largest;
|
14
|
+
$result: $result * 10 + 1;
|
15
|
+
}
|
16
|
+
@else {
|
17
|
+
$result: $result * 10;
|
18
|
+
}
|
19
|
+
|
20
|
+
$largest: $largest / 2;
|
21
|
+
}
|
22
|
+
|
23
|
+
@return $result;
|
24
|
+
}
|
@@ -1,16 +1,16 @@
|
|
1
|
-
// Returns largest power of 2 lesser than $value
|
2
|
-
// ---
|
3
|
-
// @param [number] $value: value
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function largest-power-of-2($value) {
|
8
|
-
$result: 1;
|
9
|
-
@while $result <= $value {
|
10
|
-
@if $result * 2 > $value {
|
11
|
-
@return $result
|
12
|
-
}
|
13
|
-
$result: $result * 2
|
14
|
-
}
|
15
|
-
@return $result
|
16
|
-
}
|
1
|
+
// Returns largest power of 2 lesser than $value
|
2
|
+
// ---
|
3
|
+
// @param [number] $value: value
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function largest-power-of-2($value) {
|
8
|
+
$result: 1;
|
9
|
+
@while $result <= $value {
|
10
|
+
@if $result * 2 > $value {
|
11
|
+
@return $result;
|
12
|
+
}
|
13
|
+
$result: $result * 2;
|
14
|
+
}
|
15
|
+
@return $result;
|
16
|
+
}
|
@@ -1,15 +1,15 @@
|
|
1
|
-
// Order arguments decreasing
|
2
|
-
// ---
|
3
|
-
// @param [number] $x: first value
|
4
|
-
// @param [number] $y: second value
|
5
|
-
// ---
|
6
|
-
// @return [number]
|
7
|
-
// ---
|
8
|
-
@function order-args($x, $y) {
|
9
|
-
@if $x >= $y {
|
10
|
-
@return $x $y;
|
11
|
-
}
|
12
|
-
@else {
|
13
|
-
@return $y $x;
|
14
|
-
}
|
15
|
-
}
|
1
|
+
// Order arguments decreasing
|
2
|
+
// ---
|
3
|
+
// @param [number] $x: first value
|
4
|
+
// @param [number] $y: second value
|
5
|
+
// ---
|
6
|
+
// @return [number]
|
7
|
+
// ---
|
8
|
+
@function order-args($x, $y) {
|
9
|
+
@if $x >= $y {
|
10
|
+
@return $x $y;
|
11
|
+
}
|
12
|
+
@else {
|
13
|
+
@return $y $x;
|
14
|
+
}
|
15
|
+
}
|
@@ -1,25 +1,27 @@
|
|
1
|
-
// Power function
|
2
|
-
// Using Compass if defined
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function power($x, $y) {
|
10
|
-
@if function-exists('pow') == true {
|
11
|
-
@return pow($x, $y)
|
12
|
-
}
|
13
|
-
|
14
|
-
$ret: 1;
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
1
|
+
// Power function
|
2
|
+
// Using Compass if defined
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function power($x, $y) {
|
10
|
+
@if function-exists('pow') == true {
|
11
|
+
@return pow($x, $y);
|
12
|
+
}
|
13
|
+
|
14
|
+
$ret: 1;
|
15
|
+
|
16
|
+
@if $y > 0 {
|
17
|
+
@for $i from 1 through $y {
|
18
|
+
$ret: $ret * $x;
|
19
|
+
}
|
20
|
+
} @else {
|
21
|
+
@for $i from $y to 0 {
|
22
|
+
$ret: $ret / $x;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
@return $ret;
|
27
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
// Returns sign of $x
|
2
|
-
// ---
|
3
|
-
// @param [number] $x: value
|
4
|
-
// ---
|
5
|
-
// @return [number]
|
6
|
-
// ---
|
7
|
-
@function sign($x) {
|
8
|
-
@return if($x > 0, 1, if($x < 0, -1, 0))
|
9
|
-
}
|
1
|
+
// Returns sign of $x
|
2
|
+
// ---
|
3
|
+
// @param [number] $x: value
|
4
|
+
// ---
|
5
|
+
// @return [number]
|
6
|
+
// ---
|
7
|
+
@function sign($x) {
|
8
|
+
@return if($x > 0, 1, if($x < 0, -1, 0));
|
9
|
+
}
|
@@ -1,22 +1,22 @@
|
|
1
|
-
// `and` bitwise operator
|
2
|
-
// $x & $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-and($x, $y) {
|
10
|
-
$args: order-args($x, $y);
|
11
|
-
$x: nth($args, 1);
|
12
|
-
$y: nth($args, 2);
|
13
|
-
$b: binary-length($x);
|
14
|
-
$res: 0;
|
15
|
-
|
16
|
-
@for $i from 0 through $b {
|
17
|
-
$h: power(2, $i);
|
18
|
-
$res: $res + $h * (floor($x / $h) % 2) * (floor($y / $h) % 2)
|
19
|
-
}
|
20
|
-
|
21
|
-
@return $res
|
22
|
-
}
|
1
|
+
// `and` bitwise operator
|
2
|
+
// $x & $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-and($x, $y) {
|
10
|
+
$args: order-args($x, $y);
|
11
|
+
$x: nth($args, 1);
|
12
|
+
$y: nth($args, 2);
|
13
|
+
$b: binary-length($x);
|
14
|
+
$res: 0;
|
15
|
+
|
16
|
+
@for $i from 0 through $b {
|
17
|
+
$h: power(2, $i);
|
18
|
+
$res: $res + $h * (floor($x / $h) % 2) * (floor($y / $h) % 2)
|
19
|
+
}
|
20
|
+
|
21
|
+
@return $res;
|
22
|
+
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
// `not` bitwise operator
|
2
|
-
// ~ $x
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: value
|
5
|
-
// ---
|
6
|
-
// @return [number]
|
7
|
-
// ---
|
8
|
-
@function bw-not($x) {
|
9
|
-
@return ($x + sign($x)) * -1
|
10
|
-
}
|
1
|
+
// `not` bitwise operator
|
2
|
+
// ~ $x
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: value
|
5
|
+
// ---
|
6
|
+
// @return [number]
|
7
|
+
// ---
|
8
|
+
@function bw-not($x) {
|
9
|
+
@return ($x + sign($x)) * -1;
|
10
|
+
}
|
@@ -1,24 +1,24 @@
|
|
1
|
-
// `or` bitwise operator
|
2
|
-
// $x | $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-or($x, $y) {
|
10
|
-
$args: order-args($x, $y);
|
11
|
-
$x: nth($args, 1);
|
12
|
-
$y: nth($args, 2);
|
13
|
-
$b: binary-length($x);
|
14
|
-
$res: 0;
|
15
|
-
|
16
|
-
@for $i from 0 through $b {
|
17
|
-
$h: power(2, $i);
|
18
|
-
$tx: floor($x / $h) % 2;
|
19
|
-
$ty: floor($y / $h) % 2;
|
20
|
-
$res: $res + $h * (($tx + $ty + $tx * $ty % 2) % 2)
|
21
|
-
}
|
22
|
-
|
23
|
-
@return $res
|
24
|
-
}
|
1
|
+
// `or` bitwise operator
|
2
|
+
// $x | $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-or($x, $y) {
|
10
|
+
$args: order-args($x, $y);
|
11
|
+
$x: nth($args, 1);
|
12
|
+
$y: nth($args, 2);
|
13
|
+
$b: binary-length($x);
|
14
|
+
$res: 0;
|
15
|
+
|
16
|
+
@for $i from 0 through $b {
|
17
|
+
$h: power(2, $i);
|
18
|
+
$tx: floor($x / $h) % 2;
|
19
|
+
$ty: floor($y / $h) % 2;
|
20
|
+
$res: $res + $h * (($tx + $ty + $tx * $ty % 2) % 2);
|
21
|
+
}
|
22
|
+
|
23
|
+
@return $res;
|
24
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
|
-
// `<<` bitwise operator
|
2
|
-
// $x << $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-shift-left($x, $y) {
|
10
|
-
@return $x * power(2, $y)
|
11
|
-
}
|
1
|
+
// `<<` bitwise operator
|
2
|
+
// $x << $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-shift-left($x, $y) {
|
10
|
+
@return $x * power(2, $y);
|
11
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
|
-
// `>>` bitwise operator
|
2
|
-
// $x >> $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-shift-right($x, $y) {
|
10
|
-
@return floor($x / power(2, $y))
|
11
|
-
}
|
1
|
+
// `>>` bitwise operator
|
2
|
+
// $x >> $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-shift-right($x, $y) {
|
10
|
+
@return floor($x / power(2, $y));
|
11
|
+
}
|
@@ -1,22 +1,22 @@
|
|
1
|
-
// `xor` bitwise operator
|
2
|
-
// $x ^ $y
|
3
|
-
// ---
|
4
|
-
// @param [number] $x: first value
|
5
|
-
// @param [number] $y: second value
|
6
|
-
// ---
|
7
|
-
// @return [number]
|
8
|
-
// ---
|
9
|
-
@function bw-xor($x, $y) {
|
10
|
-
$args: order-args($x, $y);
|
11
|
-
$x: nth($args, 1);
|
12
|
-
$y: nth($args, 2);
|
13
|
-
$b: binary-length($x);
|
14
|
-
$res: 0;
|
15
|
-
|
16
|
-
@for $i from 0 through $b {
|
17
|
-
$h: power(2, $i);
|
18
|
-
$res: $res + $h * (((floor($x / $h) % 2) + (floor($y / $h) % 2)) % 2)
|
19
|
-
}
|
20
|
-
|
21
|
-
@return $res
|
22
|
-
}
|
1
|
+
// `xor` bitwise operator
|
2
|
+
// $x ^ $y
|
3
|
+
// ---
|
4
|
+
// @param [number] $x: first value
|
5
|
+
// @param [number] $y: second value
|
6
|
+
// ---
|
7
|
+
// @return [number]
|
8
|
+
// ---
|
9
|
+
@function bw-xor($x, $y) {
|
10
|
+
$args: order-args($x, $y);
|
11
|
+
$x: nth($args, 1);
|
12
|
+
$y: nth($args, 2);
|
13
|
+
$b: binary-length($x);
|
14
|
+
$res: 0;
|
15
|
+
|
16
|
+
@for $i from 0 through $b {
|
17
|
+
$h: power(2, $i);
|
18
|
+
$res: $res + $h * (((floor($x / $h) % 2) + (floor($y / $h) % 2)) % 2);
|
19
|
+
}
|
20
|
+
|
21
|
+
@return $res;
|
22
|
+
}
|
@@ -1,45 +1,51 @@
|
|
1
|
-
// Checks whether argument list is valid
|
2
|
-
// ---
|
3
|
-
// @param [list] $args: argument list
|
4
|
-
// ---
|
5
|
-
// @return [bool]
|
6
|
-
// ---
|
7
|
-
@function arguments-validator($args) {
|
8
|
-
$
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
}
|
1
|
+
// Checks whether argument list is valid
|
2
|
+
// ---
|
3
|
+
// @param [list] $args: argument list
|
4
|
+
// ---
|
5
|
+
// @return [bool]
|
6
|
+
// ---
|
7
|
+
@function arguments-validator($args) {
|
8
|
+
$last: null;
|
9
|
+
$operators: (
|
10
|
+
'&' : 'and',
|
11
|
+
'|' : 'or',
|
12
|
+
'^' : 'xor',
|
13
|
+
'<<' : 'shift-left',
|
14
|
+
'>>' : 'shift-right'
|
15
|
+
);
|
16
|
+
|
17
|
+
@if length($args) < 2 {
|
18
|
+
@return false;
|
19
|
+
}
|
20
|
+
|
21
|
+
@each $current in $args {
|
22
|
+
@if map-has-key($operators, $current) {
|
23
|
+
@if not $last {
|
24
|
+
@warn "You can't start with another operator than `~`.";
|
25
|
+
@return false;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
@else if $current == '~' {
|
30
|
+
@if type-of($last) == "number" {
|
31
|
+
@warn "Operator `~` can't follow a number.";
|
32
|
+
@return false;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
@else if type-of($current) == "number" {
|
37
|
+
@if type-of($last) == "number" {
|
38
|
+
@warn "A number can't follow a number. They must be separated by an operator";
|
39
|
+
@return false;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
@else {
|
44
|
+
@return false;
|
45
|
+
}
|
46
|
+
|
47
|
+
$last: $current;
|
48
|
+
}
|
49
|
+
|
50
|
+
@return true;
|
51
|
+
}
|
@@ -1,16 +1,15 @@
|
|
1
|
-
@import "SassyBitwise/helpers/
|
2
|
-
@import "SassyBitwise/helpers/
|
3
|
-
@import "SassyBitwise/helpers/
|
4
|
-
@import "SassyBitwise/helpers/
|
5
|
-
@import "SassyBitwise/helpers/
|
6
|
-
@import "SassyBitwise/helpers/
|
7
|
-
@import "SassyBitwise/helpers/binary-length";
|
8
|
-
@import "SassyBitwise/validators/
|
9
|
-
@import "SassyBitwise/
|
10
|
-
@import "SassyBitwise/operators/
|
11
|
-
@import "SassyBitwise/operators/
|
12
|
-
@import "SassyBitwise/operators/
|
13
|
-
@import "SassyBitwise/operators/
|
14
|
-
@import "SassyBitwise/operators/shift-
|
15
|
-
@import "SassyBitwise/
|
16
|
-
@import "SassyBitwise/api/bitwise";
|
1
|
+
@import "SassyBitwise/helpers/order-args";
|
2
|
+
@import "SassyBitwise/helpers/power";
|
3
|
+
@import "SassyBitwise/helpers/sign";
|
4
|
+
@import "SassyBitwise/helpers/binary-to-decimal";
|
5
|
+
@import "SassyBitwise/helpers/decimal-to-binary";
|
6
|
+
@import "SassyBitwise/helpers/largest-power-of-2";
|
7
|
+
@import "SassyBitwise/helpers/binary-length";
|
8
|
+
@import "SassyBitwise/validators/arguments-validator";
|
9
|
+
@import "SassyBitwise/operators/or";
|
10
|
+
@import "SassyBitwise/operators/xor";
|
11
|
+
@import "SassyBitwise/operators/and";
|
12
|
+
@import "SassyBitwise/operators/not";
|
13
|
+
@import "SassyBitwise/operators/shift-left";
|
14
|
+
@import "SassyBitwise/operators/shift-right";
|
15
|
+
@import "SassyBitwise/api/bitwise";
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SassyBitwise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugo Giraudel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -47,7 +47,6 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- CHANGELOG.md
|
49
49
|
- lib/SassyBitwise.rb
|
50
|
-
- stylesheets/_SassyBitwise.scss
|
51
50
|
- stylesheets/SassyBitwise/api/_bitwise.scss
|
52
51
|
- stylesheets/SassyBitwise/helpers/_binary-length.scss
|
53
52
|
- stylesheets/SassyBitwise/helpers/_binary-to-decimal.scss
|
@@ -63,7 +62,7 @@ files:
|
|
63
62
|
- stylesheets/SassyBitwise/operators/_shift-right.scss
|
64
63
|
- stylesheets/SassyBitwise/operators/_xor.scss
|
65
64
|
- stylesheets/SassyBitwise/validators/_arguments-validator.scss
|
66
|
-
- stylesheets/
|
65
|
+
- stylesheets/_SassyBitwise.scss
|
67
66
|
homepage: http://github.com/HugoGiraudel/SassyBitwise
|
68
67
|
licenses: []
|
69
68
|
metadata: {}
|
@@ -83,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
82
|
version: 1.3.6
|
84
83
|
requirements: []
|
85
84
|
rubyforge_project: SassyBitwise
|
86
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.2.2
|
87
86
|
signing_key:
|
88
87
|
specification_version: 4
|
89
88
|
summary: An implementation of bitwise operators in Sass without the use of Ruby.
|