CFx SDK Documentation
2020SP3
SDK
CFx
dd_inc
OdRound.h
Go to the documentation of this file.
1
// Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3
// All rights reserved.
4
//
5
// This software and its documentation and related materials are owned by
6
// the Alliance. The software may only be incorporated into application
7
// programs owned by members of the Alliance, subject to a signed
8
// Membership Agreement and Supplemental Software License Agreement with the
9
// Alliance. The structure and organization of this software are the valuable
10
// trade secrets of the Alliance and its suppliers. The software is also
11
// protected by copyright law and international treaty provisions. Application
12
// programs incorporating this software must include the following statement
13
// with their copyright notices:
14
//
15
// This application incorporates Teigha(R) software pursuant to a license
16
// agreement with Open Design Alliance.
17
// Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18
// All rights reserved.
19
//
20
// By use of this software, its documentation or related materials, you
21
// acknowledge and accept the above terms.
23
24
25
26
27
#ifndef _ODROUND_INCLUDED_
28
#define _ODROUND_INCLUDED_
29
30
#include <math.h>
31
#include <limits.h>
32
33
inline
double
OdRound
(
double
a)
34
{
35
double
aFloor = ::floor(a);
36
if
(a-aFloor >= 0.5)
37
return
aFloor+1.0;
38
return
aFloor;
39
}
40
41
42
inline
long
OdRoundToLong
(
double
a)
43
{
44
if
(a >= 0.)
45
{
46
a += .5;
47
if
(a >
double
(LONG_MAX))
48
throw
OdError
(eArithmeticOverflow);
49
return
long(a);
50
}
51
else
52
{
53
a -= .5;
54
if
(a <
double
(LONG_MIN))
55
throw
OdError
(eArithmeticOverflow);
56
return
long(a);
57
}
58
}
59
60
inline
long
OdTruncateToLong
(
double
a)
61
{
62
if
(a >= 0.)
63
{
64
a += .5;
65
if
(a >
double
(LONG_MAX))
66
return
LONG_MAX;
67
else
68
return
long(a);
69
}
70
else
71
{
72
a -= .5;
73
if
(a <
double
(LONG_MIN))
74
return
LONG_MIN;
75
else
76
return
long(a);
77
}
78
}
79
80
#endif //#ifndef _ODROUND_INCLUDED_
OdTruncateToLong
long OdTruncateToLong(double a)
Definition:
OdRound.h:60
OdRoundToLong
long OdRoundToLong(double a)
Definition:
OdRound.h:42
OdError
Definition:
OdError.h:43
OdRound
double OdRound(double a)
Definition:
OdRound.h:33
Generated on Mon Oct 12 2020 11:49:43