🏠 back to Observable

How do I add the "cephes" library of math functions?

I expect this is a very basic problem, but I’ve tried for hours to get the cephes library to work, and I’m not sure what I am doing wrong.

unpkg: https://unpkg.com/cephes@1.2.0/index.js

I also found this notebook about how to require stubborn modules: 🤔 How to: require stubborn modules / Observable / Observable

Does anyone know the magic words to make cephes work, and how I could learn to troubleshoot something like this in the future?

1 Like

Using the Module require debugger, I discovered that the following might work:

cephes = require("https://bundle.run/cephes@1.2.0")

I’m certainly no expert on cephes, which I guess is a large library of special functions. At the very least, it seems to produce the correct plot of an Airy function:

Or at least it does in notebook:

2 Likes

Fantastic! This works perfectly, and I’ll definitely be using that module debugger in the future. You saved me days worth of headaches, I can’t thank you enough!

1 Like

I’m glad to hear it! I do hope it works for you but it seems a little unstable to me. I’m getting an error when I try to embed an iFrame. That same error seems to occasionally appear in notebook, but not always.

According to the docs you need to wait for the compilation to finish:

cephes = {
  const c = await require("https://bundle.run/cephes@1.2.0");
  await c.compiled;
  return c;
}
3 Likes

That works just as well for me, and if it is more stable, I’ll use that instead. Thanks again to both of you