Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minusをnegativeにrename #13

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ console.log(ui); // UInt64 { buffer: <Buffer 12 34 56 78 9a bc de f0> }
console.log(ui.toSigned()); // Int64 { buffer: <Buffer 12 34 56 78 9a bc de f0> }
```

* toMinus() (only Int64)
* toNegative() (only Int64)
```js
let i = new Int64(0x12345678, 0x9abcdef0);
console.log(i.toMinus()); // Int64 { buffer: <Buffer ed cb a9 87 65 43 21 10> }
console.log(i.toNegative()); // Int64 { buffer: <Buffer ed cb a9 87 65 43 21 10> }
```

## License
Expand Down
28 changes: 14 additions & 14 deletions __tests__/int64.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('Int64', () => {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
])))
})
test('high minus', () => {
test('high negative', () => {
const i = new Int64(0x80402010, 0x0)
expect(i.shiftRight(2)).toEqual(new Int64(Buffer.from([
0xe0, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00
Expand All @@ -160,7 +160,7 @@ describe('Int64', () => {
])))
expect(i.shiftRight(64)).toEqual(i)
})
test('normal minus', () => {
test('normal negative', () => {
const i = new Int64(0x80402010, 0x80402010)
expect(i.shiftRight(2)).toEqual(new Int64(Buffer.from([
0xe0, 0x10, 0x08, 0x04, 0x20, 0x10, 0x08, 0x04
Expand Down Expand Up @@ -212,7 +212,7 @@ describe('Int64', () => {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
])))
})
test('high minus', () => {
test('high negative', () => {
const i = new Int64(0x80402010, 0x0)
expect(i.shiftRight(2, true)).toEqual(new Int64(Buffer.from([
0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00
Expand All @@ -231,7 +231,7 @@ describe('Int64', () => {
])))
expect(i.shiftRight(64, true)).toEqual(i)
})
test('normal minus', () => {
test('normal negative', () => {
const i = new Int64(0x80402010, 0x80402010)
expect(i.shiftRight(2, true)).toEqual(new Int64(Buffer.from([
0x20, 0x10, 0x08, 0x04, 0x20, 0x10, 0x08, 0x04
Expand Down Expand Up @@ -368,32 +368,32 @@ describe('Int64', () => {
const i = new Int64(0x12345678, 0x9abcdef0)
expect(i.mul(new Int64(0x12345678, 0x9abcdef0))).toEqual(new Int64(0xa5e20890, 0xf2a52100))
})
test('mul minus', () => {
test('mul negative', () => {
const i = new Int64(0x12345678, 0x9abcdef0)
expect(i.mul(new Int64(0xffffffff, 0xfffffffe))).toEqual(new Int64(0xdb97530e, 0xca864220))
})
test('mul low int minus', () => {
test('mul low int negative', () => {
const i = new Int64(0x12345678, 0x9abcdef0)
expect(i.mul(new Int64(0x0, 0x12345678).toMinus())).toEqual(new Int64(0xd70a3d71, 0xdbd2df80))
expect(i.mul(new Int64(0x0, 0x12345678).toNegative())).toEqual(new Int64(0xd70a3d71, 0xdbd2df80))
})
test('mul int64 minus', () => {
test('mul int64 negative', () => {
const i = new Int64(0x12345678, 0x9abcdef0)
expect(i.mul(i.toMinus())).toEqual(new Int64(0x5a1df76f, 0x0d5adf00))
expect(i.mul(i.toNegative())).toEqual(new Int64(0x5a1df76f, 0x0d5adf00))
})
})
describe('toMinus', () => {
test('toMinus', () => {
describe('toNegative', () => {
test('toNegative', () => {
let i = new Int64(0x0, 0x1)
expect(i.toMinus()).toEqual(new Int64(0xffffffff, 0xffffffff))
expect(i.toNegative()).toEqual(new Int64(0xffffffff, 0xffffffff))
i = new Int64(0x12345678, 0x9abcdef0)
expect(i.toMinus()).toEqual(new Int64(0xedcba987, 0x65432110))
expect(i.toNegative()).toEqual(new Int64(0xedcba987, 0x65432110))
})
})
})

describe('UInt64', () => {
describe('shiftRight', () => {
test('high minus', () => {
test('high negative', () => {
const i = new UInt64(0x80402010, 0x0)
expect(i.shiftRight(2)).toEqual(new UInt64(Buffer.from([
0x20, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00
Expand Down
2 changes: 1 addition & 1 deletion src/int64.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class Int64 extends Int64Base {
return new UInt64(this.toBuffer())
}

toMinus () {
toNegative () {
return this.xor(UInt64.Max).add(new Int64(0x0, 0x1))
}
}
Expand Down