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

Roots not ready on quadratic equation example #6

Open
Tippon opened this issue Sep 1, 2020 · 2 comments
Open

Roots not ready on quadratic equation example #6

Tippon opened this issue Sep 1, 2020 · 2 comments

Comments

@Tippon
Copy link

Tippon commented Sep 1, 2020

Hi :)

I've been following the examples from the free Raspberry Pi page, and got to the quadratic equations example.

Everything seems to install and update correctly, and running the 'node test.js' example works perfectly. When I run the 'node server.js' command, it starts to go wrong though. I get the 'Listening at http://localhost:8080' message, but as soon as I open the calculator I get a 'The roots are not ready' error, and when I enter any values into the calculator and press Solve, nothing happens on the calculator page, but on the Visual Studio page, the terminal gives me a long error message. I can't copy and paste it, so I've attached a screenshot.
Quadratic Equation Error

@juntao
Copy link
Member

juntao commented Sep 1, 2020

This indicates a runtime error in your Rust code. Can you post a gist of your lib.rs file?

@Tippon
Copy link
Author

Tippon commented Sep 1, 2020

Thanks for the reply :)

I just noticed that I'd somehow missed the first two lines, so mine was

#[wasm_bindgen] pub fn solve(params: &str) -> String { let ps: (f32, f32, f32) = serde_json::from_str(&params).unwrap(); let discriminant: f32 = (ps.1 * ps.1) - (4. * ps.0 * ps.2); let mut solution: (f32, f32) = (0., 0.); if discriminant >= 0. { solution.0 = (((-1.) * ps.1) + discriminant.sqrt()) / (2. * ps.0); solution.1 = (((-1.) * ps.1) - discriminant.sqrt()) / (2. * ps.0); return serde_json::to_string(&solution).unwrap(); } else { return String::from("not real numbers"); } }

but I've just changed it to include the missing lines. Using VS on Windows 10 or Ubuntu 20.04 still gives the error above.

I'm pretty much brand new to this, so there's a good chance that I've got something basic wrong. At the beginning of the Getting started with Rust functions in Node.js article I used the git clone https://github.com/second-state/ssvm-nodejs-starter command to get the files, so tried the same with the quadratic equation example, but it wouldn't work. Googling told me to go to the root, so wasm-learning, and use git clone there. I've then gone to the nodejs/quadratic/ folder and worked from there, including telling VS to open it in the terminal. As far as I can tell, everything has run from that folder.

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

No branches or pull requests

2 participants