Skip to content

Commit

Permalink
fix julian examples, reference common.FloorDiv, clarify doc for FloorDiv
Browse files Browse the repository at this point in the history
  • Loading branch information
soniakeys committed Mar 11, 2013
1 parent c8a2784 commit 49c22b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions common/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Horner(x float64, c []float64) float64 {
return y
}

// FloorDiv returns the floor of x / y.
// FloorDiv returns the integer floor of the fractional value (x / y).
//
// It uses integer math only, so is more efficient than using floating point
// intermediate values. This function can be used in many places where INT()
Expand All @@ -42,7 +42,7 @@ func FloorDiv(x, y int) int {
return x/y - 1
}

// FloorDiv64 returns the floor of x / y.
// FloorDiv64 returns the integer floor of the fractional value (x / y).
//
// It uses integer math only, so is more efficient than using floating point
// intermediate values. This function can be used in many places where INT()
Expand Down
8 changes: 8 additions & 0 deletions julian/julian.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
// License MIT: http://www.opensource.org/licenses/MIT

// Julian: Chapter 7, Julian day.
//
// Under "General remarks", Meeus describes the INT function as used in the
// book. In some contexts, math.Floor might be suitable, but I think more
// often, the functions common.FloorDiv or common.FloorDiv64 will be more
// appropriate. See documentation in package common.
//
// On p. 63, Modified Julian Day is defined. See constant JMod in package
// common.
package julian

import (
Expand Down
14 changes: 7 additions & 7 deletions julian/julian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func ExampleCalendarGregorianToJD_halley() {
// Example 7.c, p. 64.
jd1 := julian.CalendarGregorianToJD(1910, 4, 20)
jd2 := julian.CalendarGregorianToJD(1986, 2, 9)
fmt.Printf("%.0f\n", jd2-jd1)
fmt.Printf("%.0f days\n", jd2-jd1)
// Output:
// 27689
// 27689 days
}

func TestGreg(t *testing.T) {
Expand Down Expand Up @@ -121,9 +121,9 @@ func TestGregLeap(t *testing.T) {
func ExampleJDToCalendar() {
// Example 7.c, p. 64.
y, m, d := julian.JDToCalendar(2436116.31)
fmt.Println("%d %d %.2f\n", y, m, d)
// Output
// 1957 10 4.81
fmt.Printf("%d %s %.2f\n", y, time.Month(m), d)
// Output:
// 1957 October 4.81
}

func TestYMD(t *testing.T) {
Expand All @@ -145,9 +145,9 @@ func TestYMD(t *testing.T) {

func ExampleDayOWeek() {
// Example 7.e, p. 65.
fmt.Println(julian.DayOfWeek(2434923.5))
fmt.Println(time.Weekday(julian.DayOfWeek(2434923.5)))
// Output:
// 3
// Wednesday
}

func ExampleDayOfYear_f() {
Expand Down

0 comments on commit 49c22b2

Please sign in to comment.