CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
OdRound.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 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#include "OdResult.h"
33
34inline double OdRound(double a)
35{
36 double aFloor = ::floor(a);
37 if(a-aFloor >= 0.5)
38 return aFloor+1.0;
39 return aFloor;
40}
41
42
43inline long OdRoundToLong(double a)
44{
45 if (a >= 0.)
46 {
47 a += .5;
48 if (a > double(LONG_MAX))
49 throw OdError(eArithmeticOverflow);
50 return long(a);
51 }
52 else
53 {
54 a -= .5;
55 if (a < double(LONG_MIN))
56 throw OdError(eArithmeticOverflow);
57 return long(a);
58 }
59}
60
61inline long OdTruncateToLong(double a)
62{
63 if (a >= 0.)
64 {
65 a += .5;
66 if (a > double(LONG_MAX))
67 return LONG_MAX;
68 else
69 return long(a);
70 }
71 else
72 {
73 a -= .5;
74 if (a < double(LONG_MIN))
75 return LONG_MIN;
76 else
77 return long(a);
78 }
79}
80
81#endif //#ifndef _ODROUND_INCLUDED_
long OdRoundToLong(double a)
Definition: OdRound.h:43
long OdTruncateToLong(double a)
Definition: OdRound.h:61
double OdRound(double a)
Definition: OdRound.h:34