JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
FixedPoint.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 *
32 */
33
34package com.jogamp.math;
35
36public class FixedPoint {
37 public static final int toFixed(int value) {
38 if (value < -32768) value = -32768;
39 if (value > 32767) value = 32767;
40 return value * 65536;
41 }
42
43 public static final int toFixed(float value) {
44 if (value < -32768) value = -32768;
45 if (value > 32767) value = 32767;
46 return (int)(value * 65536.0f);
47 }
48
49 public static final float toFloat(final int value) {
50 return value/65536.0f;
51 }
52
53 public static final int mult(final int x1, final int x2) {
54 return (int) ( ((long)x1*(long)x2)/65536 );
55 }
56
57 public static final int div(final int x1, final int x2) {
58 return (int) ( (((long)x1)<<16)/x2 );
59 }
60}
61
static final float toFloat(final int value)
Definition: FixedPoint.java:49
static final int mult(final int x1, final int x2)
Definition: FixedPoint.java:53
static final int div(final int x1, final int x2)
Definition: FixedPoint.java:57
static final int toFixed(float value)
Definition: FixedPoint.java:43
static final int toFixed(int value)
Definition: FixedPoint.java:37