Skip to content

Commit

Permalink
rename package common to base
Browse files Browse the repository at this point in the history
  • Loading branch information
soniakeys committed Mar 14, 2013
1 parent 6777b45 commit 1ad83a7
Show file tree
Hide file tree
Showing 29 changed files with 354 additions and 354 deletions.
72 changes: 36 additions & 36 deletions angle/angle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,55 @@ import (
"testing"

"github.com/soniakeys/meeus/angle"
"github.com/soniakeys/meeus/common"
"github.com/soniakeys/meeus/base"
"github.com/soniakeys/meeus/julian"
)

func ExampleSep() {
// Example 17.a, p. 110.
r1 := common.NewRA(14, 15, 39.7).Rad()
d1 := common.NewAngle(false, 19, 10, 57).Rad()
r2 := common.NewRA(13, 25, 11.6).Rad()
d2 := common.NewAngle(true, 11, 9, 41).Rad()
r1 := base.NewRA(14, 15, 39.7).Rad()
d1 := base.NewAngle(false, 19, 10, 57).Rad()
r2 := base.NewRA(13, 25, 11.6).Rad()
d2 := base.NewAngle(true, 11, 9, 41).Rad()
d := angle.Sep(r1, d1, r2, d2)
fmt.Println(common.NewFmtAngle(d))
fmt.Println(base.NewFmtAngle(d))
// Output:
// 32°47′35″
}

// First exercise, p. 110.
func TestSep(t *testing.T) {
r1 := common.NewRA(4, 35, 55.2).Rad()
d1 := common.NewAngle(false, 16, 30, 33).Rad()
r2 := common.NewRA(16, 29, 24).Rad()
d2 := common.NewAngle(true, 26, 25, 55).Rad()
r1 := base.NewRA(4, 35, 55.2).Rad()
d1 := base.NewAngle(false, 16, 30, 33).Rad()
r2 := base.NewRA(16, 29, 24).Rad()
d2 := base.NewAngle(true, 26, 25, 55).Rad()
d := angle.Sep(r1, d1, r2, d2)
answer := common.NewAngle(false, 169, 58, 0).Rad()
answer := base.NewAngle(false, 169, 58, 0).Rad()
if math.Abs(d-answer) > 1e-4 {
t.Fatal(common.NewFmtAngle(d))
t.Fatal(base.NewFmtAngle(d))
}
}

var (
r1 = []float64{
common.NewRA(10, 29, 44.27).Rad(),
common.NewRA(10, 36, 19.63).Rad(),
common.NewRA(10, 43, 01.75).Rad(),
base.NewRA(10, 29, 44.27).Rad(),
base.NewRA(10, 36, 19.63).Rad(),
base.NewRA(10, 43, 01.75).Rad(),
}
d1 = []float64{
common.NewAngle(false, 11, 02, 05.9).Rad(),
common.NewAngle(false, 10, 29, 51.7).Rad(),
common.NewAngle(false, 9, 55, 16.7).Rad(),
base.NewAngle(false, 11, 02, 05.9).Rad(),
base.NewAngle(false, 10, 29, 51.7).Rad(),
base.NewAngle(false, 9, 55, 16.7).Rad(),
}
r2 = []float64{
common.NewRA(10, 33, 29.64).Rad(),
common.NewRA(10, 33, 57.97).Rad(),
common.NewRA(10, 34, 26.22).Rad(),
base.NewRA(10, 33, 29.64).Rad(),
base.NewRA(10, 33, 57.97).Rad(),
base.NewRA(10, 34, 26.22).Rad(),
}
d2 = []float64{
common.NewAngle(false, 10, 40, 13.2).Rad(),
common.NewAngle(false, 10, 37, 33.4).Rad(),
common.NewAngle(false, 10, 34, 53.9).Rad(),
base.NewAngle(false, 10, 40, 13.2).Rad(),
base.NewAngle(false, 10, 37, 33.4).Rad(),
base.NewAngle(false, 10, 34, 53.9).Rad(),
}
jd1 = julian.CalendarGregorianToJD(1978, 9, 13)
jd3 = julian.CalendarGregorianToJD(1978, 9, 15)
Expand All @@ -71,7 +71,7 @@ func TestMinSep(t *testing.T) {
}
answer := .5017 * math.Pi / 180 // on p. 111
if math.Abs((sep-answer)/sep) > 1e-3 {
t.Fatal(common.NewFmtAngle(sep))
t.Fatal(base.NewFmtAngle(sep))
}
}

Expand All @@ -83,32 +83,32 @@ func TestMinSepRect(t *testing.T) {
}
answer := 224 * math.Pi / 180 / 3600 // on p. 111
if math.Abs((sep-answer)/sep) > 1e-2 {
t.Fatal(common.NewFmtAngle(sep))
t.Fatal(base.NewFmtAngle(sep))
}

}

func TestSepHav(t *testing.T) {
// Example 17.a, p. 110.
r1 := common.NewRA(14, 15, 39.7).Rad()
d1 := common.NewAngle(false, 19, 10, 57).Rad()
r2 := common.NewRA(13, 25, 11.6).Rad()
d2 := common.NewAngle(true, 11, 9, 41).Rad()
r1 := base.NewRA(14, 15, 39.7).Rad()
d1 := base.NewAngle(false, 19, 10, 57).Rad()
r2 := base.NewRA(13, 25, 11.6).Rad()
d2 := base.NewAngle(true, 11, 9, 41).Rad()
d := angle.SepHav(r1, d1, r2, d2)
s := fmt.Sprint(common.NewFmtAngle(d))
s := fmt.Sprint(base.NewFmtAngle(d))
if s != "32°47′35″" {
t.Fatal(s)
}
}

func ExampleSepPauwels() {
// Example 17.b, p. 116.
r1 := common.NewRA(14, 15, 39.7).Rad()
d1 := common.NewAngle(false, 19, 10, 57).Rad()
r2 := common.NewRA(13, 25, 11.6).Rad()
d2 := common.NewAngle(true, 11, 9, 41).Rad()
r1 := base.NewRA(14, 15, 39.7).Rad()
d1 := base.NewAngle(false, 19, 10, 57).Rad()
r2 := base.NewRA(13, 25, 11.6).Rad()
d2 := base.NewAngle(true, 11, 9, 41).Rad()
d := angle.SepPauwels(r1, d1, r2, d2)
fmt.Println(common.NewFmtAngle(d))
fmt.Println(base.NewFmtAngle(d))
// Output:
// 32°47′35″
}
4 changes: 2 additions & 2 deletions common/doc.go → base/doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 Sonia Keys
// License MIT: http://www.opensource.org/licenses/MIT

// Common: Functions and other definitions useful with multiple packages.
// Base: Functions and other definitions useful with multiple packages.
//
// AA begins with an unnumbered chapter titled "Some Symbols and
// Abbreviations." In addition to a list of symbols and abbreviations
Expand Down Expand Up @@ -101,4 +101,4 @@
// specified width. Larger values cause overflow.
//
// +Inf, -Inf, and NaN always cause overflow.
package common
package base
2 changes: 1 addition & 1 deletion common/julian.go → base/julian.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 Sonia Keys
// License MIT: http://www.opensource.org/licenses/MIT

package common
package base

// Julian and Besselian years described in chapter 21, Precession.

Expand Down
2 changes: 1 addition & 1 deletion common/math.go → base/math.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 Sonia Keys
// License MIT: http://www.opensource.org/licenses/MIT

package common
package base

import "math"

Expand Down
14 changes: 7 additions & 7 deletions common/math_test.go → base/math_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2012 Sonia Keys
// License MIT: http://www.opensource.org/licenses/MIT

package common_test
package base_test

import (
"fmt"
"math"
"testing"

"github.com/soniakeys/meeus/common"
"github.com/soniakeys/meeus/base"
)

// Section "Trigonometric functions of large angles":
Expand Down Expand Up @@ -37,11 +37,11 @@ func ExamplePMod_integer() {
fmt.Println("Sin Mod: ", math.Sin(math.Mod(large, 360)*math.Pi/180))

// Use of PMod on integer constants produces results identical to above.
fmt.Println("PMod int: ", math.Sin(common.PMod(large, 360)*math.Pi/180))
fmt.Println("PMod int: ", math.Sin(base.PMod(large, 360)*math.Pi/180))

// As soon as the large integer is scaled to a non-integer value though,
// precision is lost and PMod is of no help recovering at this point.
fmt.Println("PMod float:", math.Sin(common.PMod(large*math.Pi/180, 2*math.Pi)))
fmt.Println("PMod float:", math.Sin(base.PMod(large*math.Pi/180, 2*math.Pi)))
// Output:
// Direct: 0.49999999995724154
// Integer 30: 0.5
Expand Down Expand Up @@ -70,8 +70,8 @@ func ExamplePMod_mars() {

// Accordingly, PMod cannot rescue any precision, whether done on degrees
// or radians.
fmt.Println("PMod deg:", math.Sin(common.PMod(W, 360)*math.Pi/180))
fmt.Println("PMod rad:", math.Sin(common.PMod(W*math.Pi/180, 2*math.Pi)))
fmt.Println("PMod deg:", math.Sin(base.PMod(W, 360)*math.Pi/180))
fmt.Println("PMod rad:", math.Sin(base.PMod(W*math.Pi/180, 2*math.Pi)))
// Output:
// Direct: 0.04290970350270464
// Reduced: 0.04290970350923273
Expand All @@ -82,7 +82,7 @@ func ExamplePMod_mars() {
// Meeus gives no test case.
// The test case here is from Wikipedia's entry on Horner's method.
func TestHorner(t *testing.T) {
y := common.Horner(3, []float64{-1, 2, -6, 2})
y := base.Horner(3, []float64{-1, 2, -6, 2})
if y != 5 {
t.Fatal("Horner")
}
Expand Down
2 changes: 1 addition & 1 deletion common/sexagesimal.go → base/sexagesimal.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 Sonia Keys
// License MIT: http://www.opensource.org/licenses/MIT

package common
package base

import (
"bytes"
Expand Down
40 changes: 20 additions & 20 deletions common/sexagesimal_test.go → base/sexagesimal_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright 2013 Sonia Keys
// License MIT: http://www.opensource.org/licenses/MIT

package common_test
package base_test

import (
"fmt"
"math"
"testing"

"github.com/soniakeys/meeus/common"
"github.com/soniakeys/meeus/base"
)

func ExampleDecSymAdd() {
formatted := "1.25"
fmt.Println("Standard decimal symbol:", formatted)
fmt.Println("Degree units, non combining decimal point: ",
common.DecSymAdd(formatted, '°'))
base.DecSymAdd(formatted, '°'))
// Output:
// Standard decimal symbol: 1.25
// Degree units, non combining decimal point: 1°.25
Expand All @@ -27,7 +27,7 @@ func ExampleDecSymCombine() {
// Note that some software may not be capable of combining or even
// rendering the combining dot.
fmt.Println("Degree units, combining form of decimal point:",
common.DecSymCombine(formatted, '°'))
base.DecSymCombine(formatted, '°'))
// Output:
// Standard decimal symbol: 1.25
// Degree units, combining form of decimal point: 1°̣25
Expand All @@ -44,64 +44,64 @@ func TestStrip(t *testing.T) {
if ad == d {
t.Fatalf("%s(%s, %c) had no effect", fName, d, sym)
}
if sd := common.DecSymStrip(ad, sym); sd != d {
if sd := base.DecSymStrip(ad, sym); sd != d {
t.Fatalf("Strip(%s, %c) returned %s expected %s",
ad, sym, sd, d)
}
}
for _, d = range []string{"1.25", "1.", "1", ".25"} {
for _, sym = range []rune{'°', '"', 'h', 'ʰ'} {
t1("DecSymAdd", common.DecSymAdd)
t1("DecSymCombine", common.DecSymCombine)
t1("DecSymAdd", base.DecSymAdd)
t1("DecSymCombine", base.DecSymCombine)
}
}
}

func ExampleDMSToDeg() {
// Example p. 7.
fmt.Printf("%.8f\n", common.DMSToDeg(false, 23, 26, 49))
fmt.Printf("%.8f\n", base.DMSToDeg(false, 23, 26, 49))
// Output:
// 23.44694444
}

func ExampleNewAngle() {
// Example negative values, p. 9.
a := common.NewAngle(true, 13, 47, 22)
fmt.Println(common.NewFmtAngle(a.Rad()))
a = common.NewAngle(true, 0, 32, 41)
a := base.NewAngle(true, 13, 47, 22)
fmt.Println(base.NewFmtAngle(a.Rad()))
a = base.NewAngle(true, 0, 32, 41)
// use # flag to force output of all three components
fmt.Printf("%#s\n", common.NewFmtAngle(a.Rad()))
fmt.Printf("%#s\n", base.NewFmtAngle(a.Rad()))
// Output:
// -13°47′22″
// -0°32′41″
}

func ExampleNewRA() {
// Example 1.a, p. 8.
a := common.NewRA(9, 14, 55.8)
a := base.NewRA(9, 14, 55.8)
fmt.Printf("%.6f\n", math.Tan(a.Rad()))
// Output:
// -0.877517
}

func ExampleFmtAngle() {
// Example p. 6
a := new(common.FmtAngle).SetDMS(false, 23, 26, 44)
a := new(base.FmtAngle).SetDMS(false, 23, 26, 44)
fmt.Println(a)
// Output:
// 23°26′44″
}

func ExampleFmtTime() {
// Example p. 6
a := new(common.FmtTime).SetHMS(false, 15, 22, 7)
a := new(base.FmtTime).SetHMS(false, 15, 22, 7)
fmt.Printf("%0s\n", a)
// Output:
// 15ʰ22ᵐ07ˢ
}

func TestOverflow(t *testing.T) {
a := new(common.FmtAngle).SetDMS(false, 23, 26, 44)
a := new(base.FmtAngle).SetDMS(false, 23, 26, 44)
if f := fmt.Sprintf("%03s", a); f != "023°26′44″" {
t.Fatal(f)
}
Expand All @@ -112,7 +112,7 @@ func TestOverflow(t *testing.T) {
}

func ExampleSplit60() {
neg, x60, seg, err := common.Split60(-123.456, 2, true)
neg, x60, seg, err := base.Split60(-123.456, 2, true)
if err != nil {
fmt.Println(err)
return
Expand Down Expand Up @@ -140,14 +140,14 @@ func TestSplit60(t *testing.T) {
{75, 1, false, 1, "15.0", nil},
// smallest valid with prec = 15 is about 4.5 seconds.
{4.500000123456789, 15, false, 0, "4.500000123456789", nil},
{9, 16, false, 0, "9", common.WidthErrorInvalidPrecision},
{10, 15, false, 0, "10", common.WidthErrorLossOfPrecision},
{9, 16, false, 0, "9", base.WidthErrorInvalidPrecision},
{10, 15, false, 0, "10", base.WidthErrorLossOfPrecision},
// one degree can have 12 digits of precision without loss.
{3600, 12, false, 60, "0.000000000000", nil},
// 360 degrees (21600 minutes) can have 9.
{360 * 3600, 9, false, 21600, "0.000000000", nil},
} {
neg, quo, rem, err := common.Split60(tc.x, tc.prec, false)
neg, quo, rem, err := base.Split60(tc.x, tc.prec, false)
if err != tc.err {
t.Logf("%#v", tc)
t.Fatal("err", err)
Expand Down
Loading

0 comments on commit 1ad83a7

Please sign in to comment.