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

Add methods with f64 std equivelant to Math object #260

Merged
merged 3 commits into from
Mar 18, 2020

Conversation

Nickforall
Copy link
Contributor

@Nickforall Nickforall commented Feb 24, 2020

I implemented some more Math functions which already have an equivelant in the rust standard library. There are still a couple more that have to be implemented, but they require a bit more work as they have some side effects or are not in the rust standard library. Those are out of scope for this PR.

List of Math object functions

@jasonwilliams
Copy link
Member

Hey this is awesome, thanks!
will take a look (sorry ive been a while)

@jasonwilliams
Copy link
Member

@Nickforall looks ok, are you planning to add tests for these?

@jasonwilliams
Copy link
Member

jasonwilliams commented Mar 6, 2020

Some errors

Math.acosh(0.999999999999);
// expected output: NaN
ParsingError: Expected token 'identifier', got '999999999999' in routine 'field access' at line 1, col 14
error: process didn't exit successfully: `target\debug\boa_cli.exe` (exit code: 1)
The terminal process terminated with exit code: 1
Math.atanh(0.5);
// // expected output: 0.549306144334055 (approximately)
ParsingError: Expected token 'identifier', got '5' in routine 'field 
access' at line 1, col 14
error: process didn't exit successfully: `target\debug\boa_cli.exe` (exit code: 1)
The terminal process terminated with exit code: 1

Looks like its not dealing with decimals properly.
Might be worth taking a look https://github.com/jasonwilliams/boa/blob/master/docs/debugging.md

@jasonwilliams
Copy link
Member

jasonwilliams commented Mar 6, 2020

decimal number parsing is a bit messed up, only if 0 is the first number
Token output for Math.atanh(0.5);

[
    Token {
        data: Identifier(      
            "Math",
        ),
        pos: Position {        
            column_number: 1,  
            line_number: 1,    
        },
    },
    Token {
        data: Punctuator(      
            Dot,
        ),
        pos: Position {        
            column_number: 5,  
            line_number: 1,    
        },
    },
    Token {
        data: Identifier(      
            "atanh",
        ),
        pos: Position {        
            column_number: 6,  
            line_number: 1,    
        },
    },
    Token {
        data: Punctuator(      
            OpenParen,
        ),
        pos: Position {        
            column_number: 11,
            line_number: 1,   
        },
    },
    Token {
        data: NumericLiteral( 
            0.0,
        ),
        pos: Position {       
            column_number: 12,
            line_number: 1,   
        },
    },
    Token {
        data: Punctuator(     
            Dot,
        ),
        pos: Position {       
            column_number: 13,
            line_number: 1,   
        },
    },
    Token {
        data: NumericLiteral( 
            5.0,
        ),
        pos: Position {       
            column_number: 14,
            line_number: 1,   
        },
    },
    Token {
        data: Punctuator(     
            CloseParen,       
        ),
        pos: Position {       
            column_number: 15,
            line_number: 1,   
        },
    },
    Token {
        data: Punctuator(
            Semicolon,
        ),
        pos: Position {
            column_number: 16,
            line_number: 1,
        },
    },
]

Copy link
Member

@jasonwilliams jasonwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented and tested

@Nickforall
Copy link
Contributor Author

Nickforall commented Mar 6, 2020 via email

@jasonwilliams
Copy link
Member

We have mini-test suite for lexing numbers, looks like 0.1 should be added:
https://github.com/jasonwilliams/boa/blob/master/boa/src/syntax/lexer/tests.rs#L384-L405

@Nickforall

This comment has been minimized.

@Nickforall
Copy link
Contributor Author

Nickforall commented Mar 9, 2020

Will rebase once #272 is merged.

@Nickforall
Copy link
Contributor Author

Rebased and added test for all methods. The tests are largely based on the docs from Mozilla

@jasonwilliams
Copy link
Member

Thanks for your contribution @Nickforall it looks good

@jasonwilliams jasonwilliams merged commit 9b8c803 into boa-dev:master Mar 18, 2020
@Nickforall Nickforall deleted the feature/math-library branch March 19, 2020 08:33
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