Java Double to doubleToScale(double val)

Here you can find the source of doubleToScale(double val)

Description

Converts a double to a 24 bit register value.

License

Open Source License

Parameter

Parameter Description
val the value from -2.0 to +1.999...

Return

the register value from -0x800000 to 0x7fffff

Declaration

public static int doubleToScale(double val) 

Method Source Code

//package com.java2s;
/* ElmGen - DSP Development Tool
 * Copyright (C)2011 - Andrew Kilpatrick.  Modified by Gary Worsham 2013 - 2014.  Look for GSW in code.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *    /* w  w  w . jav a 2s . co m*/
 */

public class Main {
    /**
     * Converts a double to a 24 bit register value. Valid range is -2.0 to +1.999...
     * 
     * @param val the value from -2.0 to +1.999...
     * @return the register value from -0x800000 to 0x7fffff
     */
    public static int doubleToScale(double val) {
        int temp = (int) (val * (double) 0x400000);
        if (temp > 0x7fffff) {
            temp = 0x7fffff;
        }
        if (temp < -0x800000) {
            temp = -0x800000;
        }
        return temp;
    }
}

Related

  1. doubleToIndex(final double x)
  2. doubleToLex(double v)
  3. doubleToPercent(double value, int precision)
  4. doubleToRational(double number)
  5. doubleToRegisters(double d)
  6. doubleToSexagesimal(double value, int precision, double hopr, double lopr)
  7. doubleToSingleQuote(String source)
  8. doubleToSingleQuotes(String str)
  9. doubleToSlider(final double min, final double max, final double value)