num

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 6 Imported by: 0

README

num — numeric & matrix utilities

import "github.com/downsized-devs/sdk-go/num"

Stability: Stable — see STABILITY.md

Features

  • SafeDivision(numerator, denominator, zeroValue) — guarded division.
  • RandomString(n) — alphanumeric random string of length n.
  • RoundFloat — round to N decimal places (see rounding.go).
  • EmptyStringSlice(length) — pre-sized []string{"", "", ...}.
  • ExcelGenerateCoords(ctx, range) — expand D10:D13 into [D10, D11, D12, D13].

Installation

go get github.com/downsized-devs/sdk-go/num

Quick Start

import "github.com/downsized-devs/sdk-go/num"

result := num.SafeDivision(10, 0, true)        // 0
random := num.RandomString(12)                  // "aB3kX..."
cells, _ := num.ExcelGenerateCoords(ctx, "A1:A3") // ["A1","A2","A3"]

API Reference

Symbol Signature
SafeDivision (numerator, denominator float64, zeroValue bool) float64
RandomString (n int) string
RoundFloat see rounding.go
EmptyStringSlice (length int) []string
ExcelGenerateCoords (ctx, range string) ([]string, error)
now private package var (time.Now), overridable in tests.

Dependencies

  • External: github.com/xuri/excelize/v2

Testing

go test ./num/...

Five test files; RandomString test overrides the now var for determinism.

Contributing

See CONTRIBUTING.md.

  • stringlib — older random-string helper.
  • convert — numeric type conversion.

Documentation

Overview

Package num contains numeric utility helpers — currently a safe division primitive that hides divide-by-zero handling behind a configurable fallback.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyStringSlice

func EmptyStringSlice(length int) []string

func ExcelGenerateCoords

func ExcelGenerateCoords(ctx context.Context, coordinateRange string) ([]string, error)

i.e. D10:D13 -> [D10, D11, D12, D13]

func RandomString

func RandomString(n int) string

Generate random string with n length

func RoundingNumber

func RoundingNumber(num float64, n int) float64

Rounding given number to n decimal place

func SafeDivision

func SafeDivision(numerator float64, denominator float64, zeroValue bool) float64

SafeDivision returns numerator/denominator. When denominator is zero the function returns 0 if zeroValue is true; otherwise it returns the numerator unchanged so callers can choose an identity value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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