Skip to content
Discussion options

You must be logged in to vote

Second approach: If you want to support Array/Matrix dims, then you can put add and subtract methods in your class definition, and then when extending mathjs add and subtract, just call those methods:

import {create, all, factory} from './src/index.js'

const createDimType = factory(
  "Dim",
  ["typed", "typeOf", "format", "config", "add", "subtract"],
  ({ typed, typeOf, format, config, add, subtract }) => {
    class Dim {
      constructor(nominal, tolerance, options) {
        if (typeOf(nominal) !== typeOf(tolerance)) {
          throw new Error(
            "Both nominal and tolerance must be of the same type: either numbers or instances of Unit"
          );
        }
        if (…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@radianrad
Comment options

radianrad Mar 30, 2025
Author Sponsor

Answer selected by radianrad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants