Numbers - craterdog/go-component-framework GitHub Wiki

Overview

A number is a primitive element that represents a mathematical complex number that maps to the Riemann Sphere. Each number has the following string format:

$number: POLAR | RECTANGULAR | IMAGINARY | REAL

The source of this format is Bali Document Notation™ (Bali) defined here.

A complex number is composed of a real and an imaginary part which may be represented in one of two ways:

  • rectangular form - with a real x and imaginary y coordinate like 3+4i
  • polar form - with a real magnitude and imaginary phase angle like 5e^~πi

The number elements support all of the standard mathematical operations on complex numbers. And since the north and south poles of the sphere map to infinity (∞) and zero (0) respectively, the mathematical operations may include dividing by zero which is equal to infinity.

UML Diagram

A Quick Example

To whet your appetite, here is some short example code that demonstrates the use of numbers.

package main

import (
	fmt "fmt"
	fra "github.com/craterdog/go-component-framework/v7"
)

func main() {
	// Retrieve the class reference.
	var class = fra.NumberClass()

	// Retrieve a class constant.
	var infinity = class.Infinity()
	fmt.Println(infinity)

	// Create some new numbers.
	var five = class.Number(5)
	fmt.Println(five)

	// Divide by infinity and zero.
	var zero = class.Quotient(five, infinity)
	fmt.Println(zero)
	fmt.Println(class.Quotient(infinity, infinity)) // This is undefined.
	fmt.Println(class.Quotient(five, zero))
	fmt.Println(class.Quotient(zero, zero)) // This is undefined.
}

Try it out in the Go Playground...