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

Rework Math.random #826

Merged
merged 3 commits into from
Sep 8, 2019
Merged

Rework Math.random #826

merged 3 commits into from
Sep 8, 2019

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Sep 7, 2019

For motivation see 1 and 2

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 7, 2019

@dcodeIO It will be great have inferring return generic types like TS does. In this case after refactoring Math we could get nice random for different types:

export namespace Math {
  export function random<T = f64>(): T {
    // use different implementations for different types of T
    ...
    return result as T;
  }
}

let rnd1 = Math.random();        // infer as Math.random<f64>()
let rnd2: u32 = Math.random();   // infer as Math.random<u32>()
let rnd3 = Math.random() as u64; // infer as Math.random<u64>()
let rnd4 = Math.random<f32>();   // infer as Math.random<f32>()

Actually this valid typescript

@dcodeIO
Copy link
Member

dcodeIO commented Sep 8, 2019

Looks good! Relevant v8 commit: v8/v8@ac66c97#diff-202872834c682708e9294600f73e4d15R114

@dcodeIO dcodeIO merged commit c65a056 into AssemblyScript:master Sep 8, 2019
@MaxGraey MaxGraey deleted the rework-math-random branch September 8, 2019 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants