Skip to content

Rework Math.random - #826

Merged
dcodeIO merged 3 commits into
AssemblyScript:masterfrom
MaxGraey:rework-math-random
Sep 8, 2019
Merged

Rework Math.random#826
dcodeIO merged 3 commits into
AssemblyScript:masterfrom
MaxGraey:rework-math-random

Conversation

@MaxGraey

@MaxGraey MaxGraey commented Sep 7, 2019

Copy link
Copy Markdown
Member

For motivation see 1 and 2

@MaxGraey

MaxGraey commented Sep 7, 2019

Copy link
Copy Markdown
Member Author

@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

dcodeIO commented Sep 8, 2019

Copy link
Copy Markdown
Member

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