math

package
v1.9.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package math provides transcendental and advanced mathematical primitives.

Transcendental Functions (R7RS 6.2.6)

  • sin, cos, tan, asin, acos, atan
  • exp, log
  • sqrt, expt

Rounding

  • floor, ceiling, truncate, round

Numeric Conversion

  • numerator, denominator
  • rationalize
  • exact-integer-sqrt

Use Extension or AddToRegistry to register all primitives.

Package math provides transcendental math functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	PrimExp  = makeComplexPrimitive("exp", cmplx.Exp)
	PrimSin  = makeComplexPrimitive("sin", cmplx.Sin)
	PrimCos  = makeComplexPrimitive("cos", cmplx.Cos)
	PrimTan  = makeComplexPrimitive("tan", cmplx.Tan)
	PrimAsin = makeComplexPrimitive("asin", cmplx.Asin)
	PrimAcos = makeComplexPrimitive("acos", cmplx.Acos)
)

Unary transcendental primitives (R7RS §6.2.6).

View Source
var AddToRegistry = Builder.AddToRegistry

AddToRegistry registers all math primitives.

View Source
var Builder = registry.NewRegistryBuilder(addPrimitives)

Builder aggregates all math registration functions.

View Source
var Extension = registry.NewExtension("math", AddToRegistry)

Extension is the math extension.

View Source
var PrimCeiling = makeRealNumberPrimitive(realNumberOp{
	name:       "ceiling",
	integerOp:  integerPassthrough,
	floatOp:    math.Ceil,
	rationalOp: rationalToInteger(math.Ceil),
})
View Source
var PrimFloor = makeRealNumberPrimitive(realNumberOp{
	name:       "floor",
	integerOp:  integerPassthrough,
	floatOp:    math.Floor,
	rationalOp: rationalToInteger(math.Floor),
})
View Source
var PrimRound = makeRealNumberPrimitive(realNumberOp{
	name:       "round",
	integerOp:  integerPassthrough,
	floatOp:    math.RoundToEven,
	rationalOp: rationalToInteger(math.RoundToEven),
})
View Source
var PrimTruncate = makeRealNumberPrimitive(realNumberOp{
	name:       "truncate",
	integerOp:  integerPassthrough,
	floatOp:    math.Trunc,
	rationalOp: rationalToInteger(math.Trunc),
})

Functions

func PrimAngle

func PrimAngle(mc *machine.MachineContext) error

PrimAngle implements the angle primitive.

func PrimAtan

func PrimAtan(mc *machine.MachineContext) error

PrimAtan implements the (atan z) and (atan y x) primitives.

func PrimDenominator

func PrimDenominator(mc *machine.MachineContext) error

PrimDenominator implements the (denominator) primitive.

func PrimExactIntegerSqrt

func PrimExactIntegerSqrt(mc *machine.MachineContext) error

PrimExactIntegerSqrt implements the (exact-integer-sqrt) primitive.

R7RS §6.2.6: Returns two non-negative exact integers s and r where n = s² + r and n < (s+1)².

func PrimExpt

func PrimExpt(mc *machine.MachineContext) error

PrimExpt implements the (expt) primitive.

func PrimFiniteQ

func PrimFiniteQ(mc *machine.MachineContext) error

PrimFiniteQ implements the (finite?) primitive.

func PrimFloorDiv

func PrimFloorDiv(mc *machine.MachineContext) error

PrimFloorDiv implements the (floor/) primitive.

R7RS §6.2.6: Returns two values: floor quotient and floor remainder.

func PrimFloorQuotient

func PrimFloorQuotient(mc *machine.MachineContext) error

PrimFloorQuotient implements the (floor-quotient) primitive.

R7RS §6.2.6: Returns the floor quotient for any real numbers.

func PrimFloorRemainder

func PrimFloorRemainder(mc *machine.MachineContext) error

PrimFloorRemainder implements the (floor-remainder) primitive.

R7RS §6.2.6: Returns the floor remainder for any real numbers.

func PrimImagPart

func PrimImagPart(mc *machine.MachineContext) error

PrimImagPart implements the (imag-part) primitive.

func PrimInfiniteQ

func PrimInfiniteQ(mc *machine.MachineContext) error

PrimInfiniteQ implements the (infinite?) primitive.

func PrimLog

func PrimLog(mc *machine.MachineContext) error

PrimLog implements the (log z) and (log z1 z2) primitives.

func PrimMagnitude

func PrimMagnitude(mc *machine.MachineContext) error

PrimMagnitude implements the (magnitude) primitive.

func PrimMakePolar

func PrimMakePolar(mc *machine.MachineContext) error

PrimMakePolar implements the (make-polar) primitive.

func PrimMakeRectangular

func PrimMakeRectangular(mc *machine.MachineContext) error

PrimMakeRectangular implements make-rectangular. R7RS §6.2.6: If both arguments are exact, the result is exact.

func PrimNanQ

func PrimNanQ(mc *machine.MachineContext) error

PrimNanQ implements the nan? primitive.

func PrimNumberToString

func PrimNumberToString(mc *machine.MachineContext) error

PrimNumberToString implements the number->string primitive.

func PrimNumerator

func PrimNumerator(mc *machine.MachineContext) error

PrimNumerator implements the numerator primitive.

func PrimRationalize

func PrimRationalize(mc *machine.MachineContext) error

PrimRationalize implements the (rationalize) primitive.

func PrimRealPart

func PrimRealPart(mc *machine.MachineContext) error

PrimRealPart implements the (real-part) primitive.

func PrimSqrt

func PrimSqrt(mc *machine.MachineContext) error

PrimSqrt implements the (sqrt) primitive.

R7RS §6.2.6: The branch cut for sqrt lies along the negative real axis, continuous with quadrant II. This means for values on the negative real axis (including those with -0.0 imaginary part), sqrt returns positive imaginary.

func PrimStringToNumber

func PrimStringToNumber(mc *machine.MachineContext) error

PrimStringToNumber implements the string->number primitive.

R7RS §6.2.7: string->number returns a number of the maximally precise representation expressed by the given string. It is an error if radix is not 2, 8, 10, or 16.

R7RS §7.1.1: The string may contain prefix directives #b, #o, #d, #x (radix) and #e, #i (exactness), in either order, up to one of each. A radix prefix in the string overrides the radix argument.

func PrimTruncateDiv

func PrimTruncateDiv(mc *machine.MachineContext) error

PrimTruncateDiv implements the truncate/ primitive.

R7RS §6.2.6: Returns two values: truncate quotient and truncate remainder.

func PrimTruncateQuotient

func PrimTruncateQuotient(mc *machine.MachineContext) error

PrimTruncateQuotient implements the truncate-quotient primitive.

R7RS §6.2.6: Returns the truncate quotient for any real numbers.

func PrimTruncateRemainder

func PrimTruncateRemainder(mc *machine.MachineContext) error

PrimTruncateRemainder implements the truncate-remainder primitive.

R7RS §6.2.6: Returns the truncate remainder for any real numbers.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL