-
-
Notifications
You must be signed in to change notification settings - Fork 21
feat(typegpu/std): implement cosh, acosh, exp2 #1317
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8d32561
introduced cosh
lursz 0e5dea5
Merge branch 'main' into feat/std-math-trigo
lursz 14cbb07
introduced cosh into Vector ops
lursz 2d52da5
acosh tests
lursz ee6a042
introduced exp2
lursz 7b19c68
exp2 tests
lursz 502a9b7
added exp2 to index
lursz 7860171
🔧
lursz 0816ba8
final fixes
lursz 29c2c85
Merge branch 'main' into feat/std-math-trigo
lursz 57ecb16
🔧
lursz f54cac5
Merge remote-tracking branch 'refs/remotes/origin/feat/std-math-trigo…
lursz 88ca842
value to snip
lursz fe674fa
Merge branch 'main' into feat/std-math-trigo
lursz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; | ||
import { acosh, isCloseTo } from '../../../src/std/index.ts'; | ||
|
||
describe('acosh', () => { | ||
it('computes acosh of a number', () => { | ||
expect(acosh(1)).toBeCloseTo(0); | ||
expect(acosh(Math.cosh(1))).toBeCloseTo(1); | ||
expect(acosh(Math.cosh(-1))).toBeCloseTo(1); | ||
}); | ||
|
||
it('computes acosh of vec2f', () => { | ||
const input = vec2f(1, Math.cosh(1)); | ||
const expected = vec2f(Math.acosh(1), 1); | ||
expect(isCloseTo(acosh(input), expected)).toBe(true); | ||
}); | ||
|
||
it('tests acosh(cosh())', () => { | ||
const input = vec2f(1, Math.cosh(1)); | ||
const expected = vec2f(Math.acosh(1), Math.acosh(Math.cosh(1))); | ||
aleksanderkatan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(isCloseTo(acosh(input), expected)).toBe(true); | ||
}); | ||
|
||
it('computes acosh of vec3f', () => { | ||
const input = vec3f(1, Math.cosh(1), Math.cosh(-1)); | ||
const expected = vec3f(Math.acosh(1), 1, 1); | ||
expect(isCloseTo(acosh(input), expected)).toBe(true); | ||
}); | ||
|
||
it('computes acosh of vec4f', () => { | ||
const input = vec4f(1, Math.cosh(1), Math.cosh(-1), Math.cosh(2)); | ||
const expected = vec4f(Math.acosh(1), 1, 1, 2); | ||
expect(isCloseTo(acosh(input), expected)).toBe(true); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { vec2f, vec3f, vec4f } from '../../../src/data/index.ts'; | ||
import { cosh, isCloseTo } from '../../../src/std/index.ts'; | ||
|
||
describe('cosh', () => { | ||
it('computes cosh of a number', () => { | ||
expect(cosh(0)).toBeCloseTo(1); | ||
expect(cosh(1)).toBeCloseTo(Math.cosh(1)); | ||
expect(cosh(-1)).toBeCloseTo(Math.cosh(-1)); | ||
}); | ||
|
||
it('computes cosh of vec2f', () => { | ||
const input = vec2f(0, 1); | ||
const expected = vec2f(Math.cosh(0), Math.cosh(1)); | ||
expect(isCloseTo(cosh(input), expected)).toBe(true); | ||
}); | ||
|
||
it('computes cosh of vec3f', () => { | ||
const input = vec3f(0, 1, -1); | ||
const expected = vec3f(Math.cosh(0), Math.cosh(1), Math.cosh(-1)); | ||
expect(isCloseTo(cosh(input), expected)).toBe(true); | ||
}); | ||
|
||
it('computes cosh of vec4f', () => { | ||
const input = vec4f(0, 1, -1, 2); | ||
const expected = vec4f( | ||
Math.cosh(0), | ||
Math.cosh(1), | ||
Math.cosh(-1), | ||
Math.cosh(2), | ||
); | ||
expect(isCloseTo(cosh(input), expected)).toBe(true); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { | ||
vec2f, | ||
vec2h, | ||
vec3f, | ||
vec3h, | ||
vec4f, | ||
vec4h, | ||
} from '../../../src/data/index.ts'; | ||
import { isCloseTo } from '../../../src/std/index.ts'; | ||
import { exp2 } from '../../../src/std/numeric.ts'; | ||
|
||
describe('exp2', () => { | ||
it('computes exp2 of a number', () => { | ||
expect(exp2(0)).toBeCloseTo(1); | ||
expect(exp2(1)).toBeCloseTo(2); | ||
expect(exp2(2)).toBeCloseTo(4); | ||
expect(exp2(-1)).toBeCloseTo(0.5); | ||
expect(exp2(-2)).toBeCloseTo(0.25); | ||
}); | ||
|
||
it('computes exp2 of vec2f', () => { | ||
const input = vec2f(0, 1); | ||
const expected = vec2f(2 ** 0, 2 ** 1); | ||
expect(isCloseTo(exp2(input), expected)).toBe(true); | ||
}); | ||
|
||
it('computes exp2 of vec3f', () => { | ||
const input = vec3f(0, 1, -1); | ||
const expected = vec3f(2 ** 0, 2 ** 1, 2 ** -1); | ||
expect(isCloseTo(exp2(input), expected)).toBe(true); | ||
}); | ||
|
||
it('computes exp2 of vec4f', () => { | ||
const input = vec4f(0, 1, -1, 2); | ||
const expected = vec4f(2 ** 0, 2 ** 1, 2 ** -1, 2 ** 2); | ||
expect(isCloseTo(exp2(input), expected)).toBe(true); | ||
}); | ||
|
||
it('computes exp2 of vec2h', () => { | ||
const input = vec2h(0, 1); | ||
const expected = vec2h(2 ** 0, 2 ** 1); | ||
const result = exp2(input); | ||
expect(result.x).toBeCloseTo(expected.x); | ||
expect(result.y).toBeCloseTo(expected.y); | ||
}); | ||
|
||
it('computes exp2 of vec3h', () => { | ||
const input = vec3h(0, 1, -1); | ||
const expected = vec3h(2 ** 0, 2 ** 1, 2 ** -1); | ||
const result = exp2(input); | ||
expect(result.x).toBeCloseTo(expected.x); | ||
expect(result.y).toBeCloseTo(expected.y); | ||
expect(result.z).toBeCloseTo(expected.z); | ||
}); | ||
|
||
it('computes exp2 of vec4h', () => { | ||
const input = vec4h(0, 1, -1, 2); | ||
const expected = vec4h(2 ** 0, 2 ** 1, 2 ** -1, 2 ** 2); | ||
const result = exp2(input); | ||
expect(result.x).toBeCloseTo(expected.x); | ||
expect(result.y).toBeCloseTo(expected.y); | ||
expect(result.z).toBeCloseTo(expected.z); | ||
expect(result.w).toBeCloseTo(expected.w); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.