Pascal中的模数

时间:2015-08-28 05:16:15

标签: c++ pascal modulus

我正在尝试将一些Pascal代码转换为C ++代码。我不知道如何翻译这部分。

Function ThetaG_JD(jd : double) : double;
var
UT,TU,GMST : double;
begin
**UT   := Frac(jd + 0.5);**
jd   := jd - UT;
TU   := (jd - 2451545.0)/36525;
GMST := 24110.54841 + TU * (8640184.812866 + TU * (0.093104 - TU * 6.2E-6));
**GMST := Modulus(GMST + 86400.0*1.00273790934*UT,86400.0);**
ThetaG_JD := twopi * GMST/86400.0;
end; {Function ThetaG_JD}

我特别遇到了我大胆的两条线。我怎样才能将其翻译成c ++?非常感谢。

2 个答案:

答案 0 :(得分:0)

在C ++中,等效函数将是:

fmod获得浮点模数

modf将浮点项目分解为其分数和整数部分(相当于Frac)。

答案 1 :(得分:0)

如果你想计算朱利安日格林威治标准恒星时间本地平均恒星时间,也许以下可以帮助你 - 写在 PowerShell

<#
    .Synopsis
    Astronomy calculations

    .Description
    Some helper functions to calculate:
    - Julian Day,
    - Greenwich Mean Sidereal time,
    - Local Mean Sidereal Time.
#>
cls

# https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation
function Get-JulianDay
{
    param ( [System.DateTime]$dt )
    $year = $dt.Year
    $month = $dt.Month
    $day = $dt.Day
    $hour = $dt.Hour
    $minute = $dt.Minute
    $second = $dt.Second
    $a = [System.Math]::Floor((14 - $month) / 12)
    $y = $year + 4800 - $a
    $m = $month + 12 * $a - 3
    $JDN = $day + [System.Math]::Floor((153 * $m + 2) / 5) + 365 * $y + [System.Math]::Floor($y / 4) - [System.Math]::Floor($y / 100) + [System.Math]::Floor($y / 400) - 32045
    $JD = $JDN + ($hour - 12) / 24 + $minute / 1440 + $second / 86400
    return ($JD)
}

# https://en.wikipedia.org/wiki/Sidereal_time#Definition
# http://aa.usno.navy.mil/faq/docs/GAST.php
function Get-GMST
{
    param ( [double]$JD )
    $D = $JD - 2451545.0
    $GMST = 18.697374558 + 24.06570982441908 * $D
    return ($GMST % 24)
}

function Get-LMST
{
    param ( [double]$gmst, [double]$longitude )
    return ( $gmst + $longitude / 15.0 )
}

# Test above functions
$current = (Get-Date).ToUniversalTime()
$jd = Get-JulianDay -dt $current
$gmst = Get-GMST -JD $jd
$longitude = 17.668487800
$lmst = Get-LMST -gmst $gmst -longitude $longitude
$lst = [timespan]::FromHours($lmst).ToString()
Write-Host "Local mean sidereal time: $lst"
相关问题